123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #!/bin/bash
-
- ######################################################
- ### things to do AFTER host/user-specific settings ###
- ######################################################
-
- ### .... ###
- ### BASH ###
- ### '''' ###
-
- __make_ps1d() {
- 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
- }
-
- __save_rv() {
- local rvfile="$RV_TMP/$$.lastrv"
- [ -w ${rvfile%/*} ] && echo $1 > $rvfile
- }
-
- make_ps1() {
- # these functions must be already defined by ~/.bash/user/*.bashrc
- # and ~/.bash/host/*.bashrc
- test -n "$SSH_CONNECTION" && local ps1u=$(make_ps1u)
- local ps1h=$(make_ps1h)
- local ps1w="$lblue\w$normal";
- local ps1G='$(__git_ps1 "(%s)")';
- local ps1g="$green$ps1G$normal";
- local ps1D='$(__make_ps1d -r)';
- local ps1d="$lred$ps1D$normal";
- echo "$ps1u@$ps1h:$ps1w$ps1g$ps1d\$ ";
- }
-
- make_ps2() {
- echo "$white>$yellow>$lyellow>$normal ";
- }
-
- # and use to assemble own PS1
- export PS1=$(make_ps1)
- export PS2=$(make_ps2)
-
- ### ...... ###
- ### OTHERS ###
- ### '''''' ###
-
- case "$TERM" in
-
- xterm*|rxvt*|screen*)
- test -n "$SSH_CONNECTION" \
- && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session
- PROMPT_COMMAND='__save_rv $?; echo -ne "\033]0;$(__make_ps1d)$__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.
- ;;
- *)
- if test -n "${BASH_COMMAND}";
- then
- echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/~})\007"
- else
- echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/~}\$\007"
- fi
- ;;
- esac
- }
- trap show_command_in_title_bar DEBUG
- ;;
-
- *)
- PROMPT_COMMAND='__save_rv $?;'
- ;;
-
- esac
|