7b84d6bea0b60cc2f971ee6120d0459d925b822c
[feisty_meow.git] / customize / 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_LOADING_DOCK/custom/scripts/pick_credentials.sh"
6
7 if [ -z "$PRIOR_TERMINAL_TITLE" ]; then
8   # save the former terminal title if we're running in X with xterm.
9 #  PRIOR_TERMINAL_TITLE=
10   which xprop &>/dev/null
11   if [ $? -eq 0 ]; then
12     if [[ "$TERM" =~ .*"xterm".* ]]; then
13       PRIOR_TERMINAL_TITLE="$(xprop -id $WINDOWID | perl -nle 'print $1 if /^WM_NAME.+= \"(.*)\"$/')"
14
15 echo "no prior title record existed, so saving prior title as '$PRIOR_TERMINAL_TITLE'"
16
17     fi
18   fi
19 fi
20
21 # force the TERM variable to a more generic version for other side.
22 # we don't want the remote side still thinking it's running xterm.
23 export TERM=linux
24
25 #hmmm: it would be good to set an interrupt handler here and
26 #      trap ctrl-c, since otherwise we are getting exited from and losing a chance
27 #      to reset the terminal title.  this actually happens a lot, since some X11
28 #      or other background process is left running and the ssh never actually quits,
29 #      forcing one to hit ctrl-c.
30
31 if [ ! -z "$keyfile" ]; then
32   \ssh -i "$keyfile" -X -C $*
33 #-c blowfish-cbc 
34 else
35   \ssh -X -C $*
36 #-c blowfish-cbc 
37 fi
38
39 if [ $? -eq 0 ]; then
40   # we don't want to emit anything extra if this is being driven by git.
41   if [ -z "$(echo $* | grep git)" ]; then
42     # re-run the terminal labeller after coming back from ssh.
43     # we check the exit value because we don't want to update this for a failed connection.
44     if [ -z "$PRIOR_TERMINAL_TITLE" ]; then
45 echo prior title nil new label
46       bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
47     else
48 echo "using prior title of '$PRIOR_TERMINAL_TITLE'"
49       bash $FEISTY_MEOW_SCRIPTS/tty/set_term_title.sh "$PRIOR_TERMINAL_TITLE"
50       # remove the value for this, since we did our job on it.
51       unset PRIOR_TERMINAL_TITLE
52     fi
53   fi
54 fi
55
56