GithubHelp home page GithubHelp logo

fboender / sshbg Goto Github PK

View Code? Open in Web Editor NEW
48.0 7.0 7.0 225 KB

Change terminal background when SSH'ing (on specific terminals)

License: MIT License

Python 100.00%
ssh color background terminal tilix xterm

sshbg's Introduction

sshbg

Change terminal background color when SSH'ing.

Important notice: I do not provide support for this repository. Please do not file feature requests for different terminals or bug reports if this setup does not work for you.

Demo

(Yes, all the hosts are actually localhost. I was lazy).

Supported emulators, caveat and problems

This doesn't work with:

  • Almost every terminal emulator in existence (Terminator, Gnome terminal, XFCE terminal, anything based on libvte). Update: Seems to work now with libvte v2.91+. Maybe older versions too.
  • When you're using ControlMaster auto in your SSH config.

The following terminal emulators are supported:

To check if your terminal is supported, paste the following in your terminal:

 echo -e "\033]11;#007F00\a"

If the background of your terminal changes to green, it is supported.

Tilix supported this in v1.7.7 and below. Since v1.7.7 it has been broken. See this bugreport. You can downgrade to v1.7.7 to get it working again.

Don't ask me for support for your specific terminal. Chances are very good that it can't be supported.

How does it work?

Black unix magic. Well, not really. Well, kinda...

SSH lets you run a local command before the connection to the remote host is established. Some terminals allow you to set the background color with an escape sequence. It's possible to detect if the SSH command has exited from the locally executed command by polling the parent process PID in the background. Combine the three and presto! Background colors.

sshbg matches (regex) entries in a configuration file against the provided hostname. That results in a profile name, which has a background color associated with it. See the "Config file" section at the bottom of this page for more info.

Installation and usage

Requirements:

  • Python v3.x+
  • A supported terminal

Clone this repo:

git clone [email protected]:fboender/sshbg.git
cd sshbg

Copy the sshbg script to some dir in your PATH, for example:

sudo cp sshbg /usr/local/bin/

Copy the sshbg.conf file to ~/.config/sshbg.conf:

cp sshbg.conf ~/.config/

Enable the LocalCommand configuration setting in your SSH config. You can do this on a host-by-host basis, or with wildcards. To enable it for all hosts, make your SSH config look like this:

$ cat ~/.ssh/config
PermitLocalCommand yes
Host *
    LocalCommand sshbg "%n"

Config file

The config file is a JSON file that looks like this:

{
    "normal_bg_color": "#000000",
    "profiles": {
        "prod": "#2F0100",
        "uat": "#1A1400",
        "test": "#011A00"
    },
    "hostnames": {
        "test.dev.local": "test",
        "uat.dev.local": "uat",
        "prod.dev.local": "prod",
        ".*-prod.*": "prod",
        "acc.*": "uat"
    }
}

The keys:

  • normal_bg_color: The normal background color of your terminal, which sshbg will reset your terminal to when the SSH command returns.
  • profiles: The list of profile names and their associated colors. You can name these whatever you want.
  • hostnames: Regular expressions that are matched against the hostname you're SSH'ign too. If the regex matches, the profile is selected.

Remarks, weirdness and bugs.

  • The hostname is the one you specify on the commandline, NOT necessarily the real remote hostname.
  • Manually chained SSH (ssh machine_a -> ssh machine_b) will not work. Automatically chained SSH (through ProxyCommand) will work.
  • When SSH exits, the terminal background color is reset to the value of normal_bg_color in the configuration file. I have not yet found a way to reset the original terminal color as defined in your terminal.
  • After the background color is set by sshbg, your terminal probably can't change the background color itself anymore. No idea why.
  • Probably a million different strange behaviours. Did I mention I don't support this project already?

License

MIT license. See LICENSE file.

sshbg's People

Contributors

fboender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.