My dotfiles. Period.

post.bashrc 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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@$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. if test -n "${BASH_COMMAND}";
  64. then
  65. echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/~})\007"
  66. else
  67. echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/~}\$\007"
  68. fi
  69. ;;
  70. esac
  71. }
  72. trap show_command_in_title_bar DEBUG
  73. ;;
  74. *)
  75. PROMPT_COMMAND='__save_rv $?;'
  76. ;;
  77. esac