My dotfiles. Period.

post.bashrc 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. ######################################################
  3. ### things to do AFTER host/user-specific settings ###
  4. ######################################################
  5. __bashum__lastrv() {
  6. local rvfile # path to return value cache file
  7. local lastrv # actual last return value
  8. local do_rm # true if we should remove the cache
  9. rvfile="$RV_TMP/$$.lastrv"
  10. lastrv="$(cat "$rvfile")"
  11. do_rm=false
  12. test "$1" == "-r" && do_rm=true
  13. if [ "0$lastrv" -gt 0 ];
  14. then
  15. echo "!$lastrv!"
  16. else
  17. echo ""
  18. fi
  19. $do_rm && rm -f "$rvfile"
  20. }
  21. __bashum__save_rv() {
  22. local rvfile="$RV_TMP/$$.lastrv"
  23. [ -w "${rvfile%/*}" ] && echo "$1" > "$rvfile"
  24. }
  25. __bashum__task_context() {
  26. local ctx # TaskWarrior context
  27. ctx=$(task _get rc.context)
  28. test -n "$ctx" || return
  29. echo -n "|$ctx"
  30. }
  31. __bashum__mkps1() {
  32. # these functions must be already defined by ~/.bash/user/*.bashrc
  33. # and ~/.bash/host/*.bashrc
  34. test -n "$SSH_CONNECTION" \
  35. && echo -n "$(__bashum__mkps1user)" # username only when on ssh
  36. echo -n "$lwhite@" # nice shiny at sign
  37. echo -n "$(__bashum__mkps1host)" # hostname colored per host
  38. echo -n "$yellow" #\
  39. echo -n '$(__bashum__task_context)' # > taskwarrior's context
  40. echo -n "$normal" #/
  41. echo -n "$lwhite:" # nice shiny colon
  42. echo -n "$lblue\w$normal" # current workdir
  43. echo -n "$green" #\
  44. echo -n '$(__git_ps1 "(%s)")' # > git's PS1
  45. echo -n "$normal" #/
  46. echo -n "$lred" #\
  47. echo -n '$(__bashum__lastrv -r)' # > last exit status (nothing if zero)
  48. echo -n "$normal" #/
  49. echo '$ ' # obligatory dollar
  50. }
  51. __bashum__mkps2() {
  52. echo "$white>$yellow>$lyellow>$normal "
  53. }
  54. # and use to assemble own PS1
  55. PS1=$(__bashum__mkps1)
  56. PS2=$(__bashum__mkps2)
  57. __bashum__set_title() {
  58. #
  59. # Show the currently running command in the terminal title:
  60. #
  61. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  62. #
  63. case "$BASH_COMMAND" in
  64. *\033]0*)
  65. # The command is trying to set the title bar as well;
  66. # this is most likely the execution of $PROMPT_COMMAND.
  67. # In any case nested escapes confuse the terminal, so don't
  68. # output them.
  69. ;;
  70. "")
  71. echo -ne "\033]0;"
  72. echo -n "$(__bashum__lastrv)$(__bashum__mkhostid)${PWD/$HOME/\~}\$"
  73. echo -ne "\007"
  74. ;;
  75. *)
  76. echo -ne "\033]0;"
  77. echo -n "${BASH_COMMAND} ($(__bashum__mkhostid)${PWD/$HOME/\~})"
  78. echo -ne "\007"
  79. ;;
  80. esac
  81. }
  82. __bashum__mkpc() {
  83. #
  84. # Compose PROMPT_COMMAND body
  85. #
  86. echo -n '__bashum__save_rv $?;'
  87. case "$TERM" in
  88. xterm*|rxvt*|screen*)
  89. echo -n 'echo -ne "\033]0;'
  90. echo -n '$(__bashum__lastrv)'
  91. echo -n "$(__bashum__mkhostid)"
  92. echo -n '${PWD/$HOME/\~}'
  93. echo -n '\$'
  94. echo -n '\007"'
  95. ;;
  96. esac
  97. }
  98. __bashum__mkhostid() {
  99. test -n "$SSH_CONNECTION" || return
  100. echo "__bashum__mkhostid(): HOSTNAME='$HOSTNAME'" >&2
  101. echo "${HOSTNAME%%.*}:"
  102. }
  103. __bashum__setup_traps() {
  104. case "$TERM" in
  105. xterm*|rxvt*|screen*) trap __bashum__set_title DEBUG ;;
  106. esac
  107. }
  108. __bashum__setup_traps
  109. PROMPT_COMMAND=$(__bashum__mkpc)
  110. tasknag