My dotfiles. Period.

post.bashrc 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 svrc='$(__save_rv $?)'
  30. local ps1u=$(make_ps1u)
  31. local ps1h=$(make_ps1h)
  32. local ps1w="$lblue\w$normal";
  33. local ps1G='$(__git_ps1 "(%s)")';
  34. local ps1g="$green$ps1G$normal";
  35. local ps1D='$(__make_ps1d)';
  36. local ps1d="$lred$ps1D$normal";
  37. echo "$svrc$ps1u@$ps1h:$ps1w$ps1g$ps1d\$ ";
  38. }
  39. make_ps2() {
  40. echo "$white>$yellow>$lyellow>$normal ";
  41. }
  42. # and use to assemble own PS1
  43. export PS1=$(make_ps1)
  44. export PS2=$(make_ps2)
  45. ### ...... ###
  46. ### OTHERS ###
  47. ### '''''' ###
  48. case "$TERM" in
  49. xterm*|rxvt*|screen*)
  50. PROMPT_COMMAND='echo -ne "\033]0;${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} (${PWD/$HOME/~})\007"
  66. else
  67. echo -ne "\033]0;${PWD/$HOME/~}\$\007"
  68. fi
  69. ;;
  70. esac
  71. }
  72. trap show_command_in_title_bar DEBUG
  73. ;;
  74. esac