2011-10-12

screen tricks

GNU screen has been a staple tool for a few years now that I do most thing on remote machines. My main hangup with it is switching windows which I do a lot and requires multiple keypresses (C-a #).  This can be alleviated some by splitting the screen (C-a S) so I don't have to switch as often. But that introduces yet another sequence of key strokes (C-a TAB). It's something I can only stomach on a larger screen since I hate terminals with too few lines.

It occurred to me today that I could open up to ssh sessions and have both joined to the same screen session, so that I could keep different windows open in each. Simply open the second terminal with "screen -x".

Another trick I discovered was to add the following to my bashrc.
if [ "$TERM" = "screen" ]; then
  screen_set_window_title () {
    local HPWD="$PWD"
    case $HPWD in
      $HOME) HPWD="~";;
      *) HPWD=`basename "$HPWD"`;;
    esac
    printf '\ek%s\e\\' "$HPWD"
  }
  PROMPT_COMMAND="screen_set_window_title; $PROMPT_COMMAND"
fi
And now my windows have a more sensible name; I do find myself constantly cycling through windows till I find the right screen in the right directory.

No comments: