My dotfiles. Period.

post.bashrc 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. ######################################################
  3. ### things to do AFTER host/user-specific settings ###
  4. ######################################################
  5. ### .... ###
  6. ### BASH ###
  7. ### '''' ###
  8. __make_ps1d() {
  9. local rvfile="$RV_TMP/$$.lastrv"
  10. local lastrv="$(cat "$rvfile")"
  11. local 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. __save_rv() {
  22. local rvfile="$RV_TMP/$$.lastrv"
  23. [ -w "${rvfile%/*}" ] && echo "$1" > "$rvfile"
  24. }
  25. make_ps1() {
  26. # these functions must be already defined by ~/.bash/user/*.bashrc
  27. # and ~/.bash/host/*.bashrc
  28. test -n "$SSH_CONNECTION" && local ps1u=$(make_ps1u)
  29. local ps1h=$(make_ps1h)
  30. local ps1w="$lblue\w$normal";
  31. local ps1G='$(__git_ps1 "(%s)")';
  32. local ps1g="$green$ps1G$normal";
  33. local ps1D='$(__make_ps1d -r)';
  34. local ps1d="$lred$ps1D$normal";
  35. echo "$ps1u$lwhite@$ps1h:$ps1w$ps1g$ps1d\$ ";
  36. }
  37. make_ps2() {
  38. echo "$white>$yellow>$lyellow>$normal ";
  39. }
  40. # and use to assemble own PS1
  41. export PS1=$(make_ps1)
  42. export PS2=$(make_ps2)
  43. ### ...... ###
  44. ### OTHERS ###
  45. ### '''''' ###
  46. case "$TERM" in
  47. xterm*|rxvt*|screen*)
  48. test -n "$SSH_CONNECTION" \
  49. && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session
  50. PROMPT_COMMAND='__save_rv $?; echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/\~}\$\007"'
  51. # Show the currently running command in the terminal title:
  52. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  53. show_command_in_title_bar()
  54. {
  55. case "$BASH_COMMAND" in
  56. *\033]0*)
  57. # The command is trying to set the title bar as well;
  58. # this is most likely the execution of $PROMPT_COMMAND.
  59. # In any case nested escapes confuse the terminal, so don't
  60. # output them.
  61. ;;
  62. "")
  63. echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/\~}\$\007"
  64. ;;
  65. *)
  66. echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/\~})\007"
  67. ;;
  68. esac
  69. }
  70. trap show_command_in_title_bar DEBUG
  71. ;;
  72. *)
  73. PROMPT_COMMAND='__save_rv $?;'
  74. ;;
  75. esac