My dotfiles. Period.

post.bashrc 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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__set_title() {
  45. #
  46. # Show the currently running command in the terminal title:
  47. #
  48. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  49. #
  50. case "$BASH_COMMAND" in
  51. *\033]0*)
  52. # The command is trying to set the title bar as well;
  53. # this is most likely the execution of $PROMPT_COMMAND.
  54. # In any case nested escapes confuse the terminal, so don't
  55. # output them.
  56. ;;
  57. "")
  58. echo -ne "\033]0;"
  59. echo -n "$(__bashum__lastrv)$(__bashum__mkhostid)${PWD/$HOME/\~}\$"
  60. echo -ne "\007"
  61. ;;
  62. *)
  63. echo -ne "\033]0;"
  64. echo -n "${BASH_COMMAND} ($(__bashum__mkhostid)${PWD/$HOME/\~})"
  65. echo -ne "\007"
  66. ;;
  67. esac
  68. }
  69. __bashum__mkpc() {
  70. #
  71. # Compose PROMPT_COMMAND body
  72. #
  73. echo -n '__bashum__save_rv $?;'
  74. case "$TERM" in
  75. xterm*|rxvt*|screen*)
  76. echo -n 'echo -ne "\033]0;'
  77. echo -n '$(__bashum__lastrv)'
  78. echo -n "$(__bashum__mkhostid)"
  79. echo -n '${PWD/$HOME/\~}'
  80. echo -n '\$'
  81. echo -n '\007"'
  82. ;;
  83. esac
  84. }
  85. __bashum__mkhostid() {
  86. test -n "$SSH_CONNECTION" || return
  87. echo "__bashum__mkhostid(): HOSTNAME='$HOSTNAME'" >&2
  88. echo"${HOSTNAME%%.*}:"
  89. }
  90. __bashum__setup_traps() {
  91. case "$TERM" in
  92. xterm*|rxvt*|screen*) trap __bashum__set_title DEBUG ;;
  93. esac
  94. }
  95. __bashum__setup_traps
  96. PROMPT_COMMAND=$(__bashum__mkpc)
  97. tasknag