#!/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__task_context() { local ctx=$(task _get rc.context) test -n "$ctx" || return echo -n "|$ctx" } __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 "$yellow" #\ echo -n '$(__bashum__task_context)' # > taskwarrior's context echo -n "$normal" #/ echo -n "$lwhite:" # nice shiny colon 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__set_title() { # # Show the currently running command in the terminal title: # # http://www.davidpashley.com/articles/xterm-titles-with-bash.html # 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;" echo -n "$(__bashum__lastrv)$(__bashum__mkhostid)${PWD/$HOME/\~}\$" echo -ne "\007" ;; *) echo -ne "\033]0;" echo -n "${BASH_COMMAND} ($(__bashum__mkhostid)${PWD/$HOME/\~})" echo -ne "\007" ;; esac } __bashum__mkpc() { # # Compose PROMPT_COMMAND body # echo -n '__bashum__save_rv $?;' case "$TERM" in xterm*|rxvt*|screen*) echo -n 'echo -ne "\033]0;' echo -n '$(__bashum__lastrv)' echo -n "$(__bashum__mkhostid)" echo -n '${PWD/$HOME/\~}' echo -n '\$' echo -n '\007"' ;; esac } __bashum__mkhostid() { test -n "$SSH_CONNECTION" || return echo "__bashum__mkhostid(): HOSTNAME='$HOSTNAME'" >&2 echo"${HOSTNAME%%.*}:" } __bashum__setup_traps() { case "$TERM" in xterm*|rxvt*|screen*) trap __bashum__set_title DEBUG ;; esac } __bashum__setup_traps PROMPT_COMMAND=$(__bashum__mkpc) tasknag