My dotfiles. Period.

post.bashrc 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if [ 0$lastrv -gt 0 ];
  13. then
  14. echo "$lastrv"
  15. else
  16. echo ""
  17. fi
  18. rm -f $rvfile
  19. }
  20. __save_rv() {
  21. local rvfile="/var/tmp/bash-rv/$$.lastrv"
  22. [ -w ${rvfile%/*} ] && echo $1 > $rvfile
  23. }
  24. make_ps1() {
  25. # these functions must be already defined by ~/.bash/user/*.bashrc
  26. # and ~/.bash/host/*.bashrc
  27. local svrc='$(__save_rv $?)'
  28. 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)';
  34. local ps1d="$lred$ps1D$normal";
  35. echo "$svrc$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. PROMPT_COMMAND='echo -ne "\033]0;${PWD/$HOME/~}\$\007"'
  49. # Show the currently running command in the terminal title:
  50. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  51. show_command_in_title_bar()
  52. {
  53. case "$BASH_COMMAND" in
  54. *\033]0*)
  55. # The command is trying to set the title bar as well;
  56. # this is most likely the execution of $PROMPT_COMMAND.
  57. # In any case nested escapes confuse the terminal, so don't
  58. # output them.
  59. ;;
  60. *)
  61. if test -n "${BASH_COMMAND}";
  62. then
  63. echo -ne "\033]0;${BASH_COMMAND} (${PWD/$HOME/~})\007"
  64. else
  65. echo -ne "\033]0;${PWD/$HOME/~}\$\007"
  66. fi
  67. ;;
  68. esac
  69. }
  70. trap show_command_in_title_bar DEBUG
  71. ;;
  72. esac