Giter VIP home page Giter VIP logo

osx-terminal-theme-ssh's Introduction

========================== Retheme OSX Terminal tabs via SSH

If you've ever managed multiple servers via SSH, you've probably accidentally send the wrong command to the wrong terminal window at one point or another.

This is easy to do. They all look the same! You can set the terminal prompts, but that's not a very good visual indicator.

The OSX terminal app provides the ability to have multiple themes, and these can provide a clear visual indication, if you remember to set them. But if it's not automatic, you're likely to forget.

This set of scripts was written to provide a way to run automated commands at the start and end of SSH sessions, based on the host name.

Before starting an SSH session, the script will check for the existence of a script at ~/.ssh/scripts/start_[SSH HOSTNAME].sh, and run it if it exists. At the end of the session, it will look for a script at ~/.ssh/scripts/stop_[SSH HOSTNAME].sh, and run that as well. Note that the hostname is based on the command line you give to SSH, so if you nickname your servers in your SSH config, name your scripts based on the nickname rather than the real host name. You can 'return' anything from your start script by simply printing it to the console. The output will then be appended to the call of your stop script as parameters

Linux Users: The example scripts use an Applescript to set the terminal theme, but you can achieve a similar affect using the 'tput' command.

The components:

  • scripts/ -- The scripts folder should be placed at ~/.ssh/scripts
    • changetheme.scpt -- An Applescript to retheme the currently active terminal tab. Takes the name of the theme as a command line parameter: osascript changetheme.scpt Ocean
    • wrapssh.sh -- This bash script should be aliased to 'ssh'. It will wrap the ssh call and run your commands at start and stop.
    • start*.sh -- Example script for changing themes for integration and production environments. It returns the terminal window id and the tab's tty to identify the tab
    • stop.sh -- Example script for changing the theme back. If a window id and a tty name is input, the corresponding tab will be searched and reset. This allows for a reset of the theme for tabs in the background i.e. if you have a broken pipe

========================== Installing

  1. Create some themes to use in your terminal settings. The example scripts expect to use "Pro" (a default in OSX), "Pro Int", and "Pro Prod"

  2. Install the 'scripts' folder in ~/.ssh/scripts

  3. Write start and stop scripts for your server, or symlink to the example scripts.

ln -s ~/.ssh/scripts/startprod.sh ~/.ssh/scripts/start\_productionserver.mydomain.com.sh ln -s ~/.ssh/scripts/stop.sh ~/.ssh/scripts/stop\_productionserver.mydomain.com.sh
  1. Test your setup by calling the wrapssh.sh script
ln -s ~/.ssh/scripts/wrapssh.sh [email protected]
  1. Edit your ~/.bash_profile to call wrapssh.sh whenever you type 'ssh'. Feel free to give it another alias if you're squeamish about totally wrapping your SSH command.
alias ssh=~/.ssh/scripts/wrapssh.sh

Note: if your SSH command is aliased to the wrapssh script, it won't work for STDIN handling (as in piping things to SSH). I don't find this to be an issue, but if you do a lot of that in your workflow, you can alias the command to something else, or directly call /usr/bin/ssh when you need to pipe through SSH.

osx-terminal-theme-ssh's People

Contributors

joekepley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ghoppe mactory

osx-terminal-theme-ssh's Issues

Thanks!

Thanks for this script, very useful!

I'm trying to figure out how to implement color changing based on destination host when I have to tunnel through the same gateway server to my destinations.

My ssh commands are like:

  1. ssh -X -L 1111:destination1.com:22 gateway.com
  2. ssh -X -L 1111:destination2.com:22 gateway.com
  3. ssh -X myplainhost.com

Grabbing the last argument works for 3) but not for 1) or 2). My shell scripting fu isn't great but I imagine LASTARG would have be set by a more complex function that checks for which situation is appropriate and therefore which argument to grab?

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.