#!/bin/bash ###################################################### ### things to do AFTER host/user-specific settings ### ###################################################### __bashum__lastrv() { local rvfile="$RV_TMP/$$.lastrv" local lastrv="$(cat "$rvfile")" local do_rm=false test "$1" == "-r" && do_rm=true if [ "0$lastrv" -gt 0 ]; then echo "!$lastrv!" else echo "" fi $do_rm && rm -f "$rvfile" } __bashum__save_rv() { local rvfile="$RV_TMP/$$.lastrv" [ -w "${rvfile%/*}" ] && echo "$1" > "$rvfile" } __bashum__mkps1() { # these functions must be already defined by ~/.bash/user/*.bashrc # and ~/.bash/host/*.bashrc test -n "$SSH_CONNECTION" \ && echo -n "$(__bashum__mkps1user)" # username only when on ssh echo -n "$lwhite@" # nice shiny at sign echo -n "$(__bashum__mkps1host):" # hostname colored per host echo -n "$lblue\w$normal" # current workdir echo -n "$green" #\ echo -n '$(__git_ps1 "(%s)")' # > git's PS1 echo -n "$normal" #/ echo -n "$lred" #\ echo -n '$(__bashum__lastrv -r)' # > last exit status (nothing if zero) echo -n "$normal" #/ echo '$ ' # obligatory dollar } __bashum__mkps2() { echo "$white>$yellow>$lyellow>$normal " } # and use to assemble own PS1 export PS1=$(__bashum__mkps1) export PS2=$(__bashum__mkps2) __bashum__setup_prompt_command() { case "$TERM" in xterm*|rxvt*|screen*) test -n "$SSH_CONNECTION" \ && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session PROMPT_COMMAND='__bashum__save_rv $?; echo -ne "\033]0;$(__bashum__lastrv)$__host_id${PWD/$HOME/\~}\$\007"' # Show the currently running command in the terminal title: # http://www.davidpashley.com/articles/xterm-titles-with-bash.html show_command_in_title_bar() { case "$BASH_COMMAND" in *\033]0*) # The command is trying to set the title bar as well; # this is most likely the execution of $PROMPT_COMMAND. # In any case nested escapes confuse the terminal, so don't # output them. ;; "") echo -ne "\033]0;$(__bashum__lastrv)$__host_id${PWD/$HOME/\~}\$\007" ;; *) echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/\~})\007" ;; esac } trap show_command_in_title_bar DEBUG ;; *) PROMPT_COMMAND='__bashum__save_rv $?;' ;; esac } __bashum__setup_prompt_command tasknag