My dotfiles. Period.

post.bashrc 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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__task_context() {
  23. local ctx=$(task _get rc.context)
  24. test -n "$ctx" || return
  25. echo -n "|$ctx"
  26. }
  27. __bashum__mkps1() {
  28. # these functions must be already defined by ~/.bash/user/*.bashrc
  29. # and ~/.bash/host/*.bashrc
  30. test -n "$SSH_CONNECTION" \
  31. && echo -n "$(__bashum__mkps1user)" # username only when on ssh
  32. echo -n "$lwhite@" # nice shiny at sign
  33. echo -n "$(__bashum__mkps1host)" # hostname colored per host
  34. echo -n "$yellow" #\
  35. echo -n '$(__bashum__task_context)' # > taskwarrior's context
  36. echo -n "$normal" #/
  37. echo -n "$lwhite:" # nice shiny colon
  38. echo -n "$lblue\w$normal" # current workdir
  39. echo -n "$green" #\
  40. echo -n '$(__git_ps1 "(%s)")' # > git's PS1
  41. echo -n "$normal" #/
  42. echo -n "$lred" #\
  43. echo -n '$(__bashum__lastrv -r)' # > last exit status (nothing if zero)
  44. echo -n "$normal" #/
  45. echo '$ ' # obligatory dollar
  46. }
  47. __bashum__mkps2() {
  48. echo "$white>$yellow>$lyellow>$normal "
  49. }
  50. # and use to assemble own PS1
  51. export PS1=$(__bashum__mkps1)
  52. export PS2=$(__bashum__mkps2)
  53. __bashum__set_title() {
  54. #
  55. # Show the currently running command in the terminal title:
  56. #
  57. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  58. #
  59. case "$BASH_COMMAND" in
  60. *\033]0*)
  61. # The command is trying to set the title bar as well;
  62. # this is most likely the execution of $PROMPT_COMMAND.
  63. # In any case nested escapes confuse the terminal, so don't
  64. # output them.
  65. ;;
  66. "")
  67. echo -ne "\033]0;"
  68. echo -n "$(__bashum__lastrv)$(__bashum__mkhostid)${PWD/$HOME/\~}\$"
  69. echo -ne "\007"
  70. ;;
  71. *)
  72. echo -ne "\033]0;"
  73. echo -n "${BASH_COMMAND} ($(__bashum__mkhostid)${PWD/$HOME/\~})"
  74. echo -ne "\007"
  75. ;;
  76. esac
  77. }
  78. __bashum__mkpc() {
  79. #
  80. # Compose PROMPT_COMMAND body
  81. #
  82. echo -n '__bashum__save_rv $?;'
  83. case "$TERM" in
  84. xterm*|rxvt*|screen*)
  85. echo -n 'echo -ne "\033]0;'
  86. echo -n '$(__bashum__lastrv)'
  87. echo -n "$(__bashum__mkhostid)"
  88. echo -n '${PWD/$HOME/\~}'
  89. echo -n '\$'
  90. echo -n '\007"'
  91. ;;
  92. esac
  93. }
  94. __bashum__mkhostid() {
  95. test -n "$SSH_CONNECTION" || return
  96. echo "__bashum__mkhostid(): HOSTNAME='$HOSTNAME'" >&2
  97. echo "${HOSTNAME%%.*}:"
  98. }
  99. __bashum__setup_traps() {
  100. case "$TERM" in
  101. xterm*|rxvt*|screen*) trap __bashum__set_title DEBUG ;;
  102. esac
  103. }
  104. __bashum__setup_traps
  105. PROMPT_COMMAND=$(__bashum__mkpc)
  106. tasknag