X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.profile.d%2Fprompt.bashrc;h=6398e3dcbb50770cbfc8f8df460103ecfa9b6f19;hp=58c2222421123284dc0fccd9857b04b84fcf2445;hb=8a304871323fd8c0ab81b81a9082f07d03a1fa0c;hpb=6d1a3c415482b587dbadc1323ff37c1319ecfd2e diff --git a/.profile.d/prompt.bashrc b/.profile.d/prompt.bashrc index 58c2222..6398e3d 100644 --- a/.profile.d/prompt.bashrc +++ b/.profile.d/prompt.bashrc @@ -1,17 +1,48 @@ -# $Id$ -# -# Set the title of an xterm to the hostname. -# - -SSH_FORWARDED=$(get_remote_ip -n) +# Set the title of an xterm to the hostname unless the remote IP is matched by +# a regular expression in ~/.ssh/forwarded. +SSH_FORWARDED=$(get_remote_ip) if [ ! -z "$SSH_FORWARDED" ]; then - if [ ! "$SSH_FORWARDED" = "10.99.10.121" -a ! "$SSH_FORWARDED" = "ip01pc" ]; then - SSH_FORWARDED=" (from $SSH_FORWARDED)" - else + if [ "$SSH_FORWARDED" = "localhost" ]; then SSH_FORWARDED= + elif [ -f ~/.ssh/forwarded ]; then + for forwarded in $(< ~/.ssh/forwarded); do + if echo "$SSH_FORWARDED" | grep "$forwarded" &>/dev/null; then + SSH_FORWARDED= + fi + done + unset forwarded fi + [ ! -z "$SSH_FORWARDED" ] && SSH_FORWARDED=" (from $(get_remote_ip -n))" fi + +# Unscientific check for grid jobs. +case ${SSH_CLIENT##* } in + ""|22|2222);; + *) SSH_FORWARDED="$SSH_FORWARDED [grid]" +esac + info="$HOSTNAME$SSH_FORWARDED" -blank=$(echo $info | sed 's/./ /g') -export PROMPT_COMMAND="echo -ne '\033]0;$info\007\r$blank\r'" -unset info blank SSH_FORWARDED + +# Check for vim. +vimchild=" [vim]" +if ps -o comm= -p $PPID 2>/dev/null | grep '^vim*$' &>/dev/null; then + # Clear [vim] when exiting. + trap "echo -ne '\\033]0;$info\\033\\0134'" exit + info="$info$vimchild" +fi +if [ "${TERM##screen}" = "$TERM" ]; then + export PROMPT_COMMAND="echo -ne '\033]0;$info\033\0134\r\033[K'" +else + export PROMPT_COMMAND='echo -ne "\033k\033\0134"' +fi +unset blank info vimchild SSH_FORWARDED + +# Actual dtterm barfs on escape sequences. +if [ "$TERMINAL_EMULATOR" = "dtterm" ]; then + unset PROMPT_COMMAND +fi + +# As does screen on an ancient Solaris host. +if [ -n "$OLDSOLARIS" -a ! "${TERM##screen}" = "$TERM" ]; then + unset PROMPT_COMMAND +fi