My dotfiles. Period.

post.bashrc 3.7KB

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