added recovery of the terminal title from before ssh resets it, but only works for...
[feisty_meow.git] / customizing / fred / scripts / ssh.sh
1 #!/bin/bash
2
3 # wraps our calling the secure shell and lets us pick our credentials.
4
5 source "$FEISTY_MEOW_GENERATED/custom/scripts/pick_credentials.sh"
6
7 # save the former terminal title if we're running in X.
8 prior_title="$(xprop -id $WINDOWID | perl -nle 'print $1 if /^WM_NAME.+= \"(.*)\"$/')"
9
10 if [ ! -z "$keyfile" ]; then
11   \ssh -i "$keyfile" -X -C -c blowfish-cbc $*
12 else
13   \ssh -X -C -c blowfish-cbc $*
14 fi
15
16 if [ $? -eq 0 ]; then
17   # we don't want to emit anything extra if this is being driven by git.
18   if [ -z "$(echo $* | grep git)" ]; then
19     # re-run the terminal labeller after coming back from ssh.
20     # we check the exit value because we don't want to update this for a failed connection.
21     if [ -z "$prior_title" ]; then
22       bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
23     else
24       bash $FEISTY_MEOW_SCRIPTS/tty/set_term_title.sh "$prior_title"
25     fi
26   fi
27 fi
28
29