My dotfiles. Period.

post.bashrc 2.1KB

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