Skip to content

rghiglianovich/macOsshcolor

Repository files navigation

macOsshcolor

This script changes the macOS Terminal.app Profile, according to the remote server name you are SSHing.

There are two ways to achieve the goal: either

you can have a custom profile for each remote server you usually use

OR you can have a json file with a collection of relations "servername":"profile name", like:

  {
    "server":"Red Sands",
    "server1":"Custom 1",
    "serverX":"Red Sands",
  }

in this way you can use the same profile for more servers.

Usage:

  • Clone https://github.com/rghiglianovich/macOsshcolor.git wherever you prefer. The script resolves its own path dynamically, so you do not need to edit hardcoded paths.

  • Make an alias:

    alias ssh="~/macOsshcolor/sshcolor.sh"
    

    You should save it into ~/.bash_profile or ~/.zshrc or wherever

  • Set up your profiles in Terminal/Preferences:

    • a Profile for Local connections, named "local"
    • another one for generic (or backup) remote: "remote"
    • all the other profiles you need.
    • copy the json file : sshcolorConfig.json.demo in sshcolorConfig.json and customize it
    • sshcolorConfig.json is now the single source of truth for local profile, remote profile and host mappings
  • The script resolves the target host through ssh -G, then uses the left part of the resolved FQDN for the matches.
    Example: for a connection like ssh john@myserver42.remote.com "myserver42" will be searched.
    This also means SSH aliases defined in ~/.ssh/config are resolved before the profile lookup.

    If the name does not have an entry in the hosts section of sshcolorConfig.json, then a Profile with the same name is searched

If the server you're connecting to doesn't match with a custom profile or with an entry on the sshcolorConfig.json file, the generic one ("remote") will be taken.

Credits

This script is inspired by Henry Tseng's one found here: https://gist.github.com/henrytseng/f58ec119d5d989a6306d769d212b7648

Releases

No releases published

Packages

 
 
 

Contributors