My dotfiles. Period.

post.bashrc 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. ######################################################
  3. ### things to do AFTER host/user-specific settings ###
  4. ######################################################
  5. __bashum__lastrv() {
  6. local rvfile="$RV_TMP/$$.lastrv"
  7. local lastrv="$(cat "$rvfile")"
  8. local do_rm=false
  9. test "$1" == "-r" && do_rm=true
  10. if [ "0$lastrv" -gt 0 ];
  11. then
  12. echo "!$lastrv!"
  13. else
  14. echo ""
  15. fi
  16. $do_rm && rm -f "$rvfile"
  17. }
  18. __bashum__save_rv() {
  19. local rvfile="$RV_TMP/$$.lastrv"
  20. [ -w "${rvfile%/*}" ] && echo "$1" > "$rvfile"
  21. }
  22. __bashum__mkps1() {
  23. # these functions must be already defined by ~/.bash/user/*.bashrc
  24. # and ~/.bash/host/*.bashrc
  25. test -n "$SSH_CONNECTION" \
  26. && echo -n "$(__bashum__mkps1user)" # username only when on ssh
  27. echo -n "$lwhite@" # nice shiny at sign
  28. echo -n "$(__bashum__mkps1host):" # hostname colored per host
  29. echo -n "$lblue\w$normal" # current workdir
  30. echo -n "$green" #\
  31. echo -n '$(__git_ps1 "(%s)")' # > git's PS1
  32. echo -n "$normal" #/
  33. echo -n "$lred" #\
  34. echo -n '$(__bashum__lastrv -r)' # > last exit status (nothing if zero)
  35. echo -n "$normal" #/
  36. echo '$ ' # obligatory dollar
  37. }
  38. __bashum__mkps2() {
  39. echo "$white>$yellow>$lyellow>$normal "
  40. }
  41. # and use to assemble own PS1
  42. export PS1=$(__bashum__mkps1)
  43. export PS2=$(__bashum__mkps2)
  44. __bashum__setup_prompt_command() {
  45. case "$TERM" in
  46. xterm*|rxvt*|screen*)
  47. test -n "$SSH_CONNECTION" \
  48. && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session
  49. PROMPT_COMMAND='__bashum__save_rv $?; echo -ne "\033]0;$(__bashum__lastrv)$__host_id${PWD/$HOME/\~}\$\007"'
  50. # Show the currently running command in the terminal title:
  51. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  52. show_command_in_title_bar()
  53. {
  54. case "$BASH_COMMAND" in
  55. *\033]0*)
  56. # The command is trying to set the title bar as well;
  57. # this is most likely the execution of $PROMPT_COMMAND.
  58. # In any case nested escapes confuse the terminal, so don't
  59. # output them.
  60. ;;
  61. "")
  62. echo -ne "\033]0;$(__bashum__lastrv)$__host_id${PWD/$HOME/\~}\$\007"
  63. ;;
  64. *)
  65. echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/\~})\007"
  66. ;;
  67. esac
  68. }
  69. trap show_command_in_title_bar DEBUG
  70. ;;
  71. *)
  72. PROMPT_COMMAND='__bashum__save_rv $?;'
  73. ;;
  74. esac
  75. }
  76. __bashum__setup_prompt_command
  77. tasknag