My dotfiles. Period.

post.bashrc 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. test -n "$SSH_CONNECTION" \
  50. && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session
  51. PROMPT_COMMAND='__save_rv $?; echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/\~}\$\007"'
  52. # Show the currently running command in the terminal title:
  53. # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
  54. show_command_in_title_bar()
  55. {
  56. case "$BASH_COMMAND" in
  57. *\033]0*)
  58. # The command is trying to set the title bar as well;
  59. # this is most likely the execution of $PROMPT_COMMAND.
  60. # In any case nested escapes confuse the terminal, so don't
  61. # output them.
  62. ;;
  63. *)
  64. if test -n "${BASH_COMMAND}";
  65. then
  66. echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/\~})\007"
  67. else
  68. echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/\~}\$\007"
  69. fi
  70. ;;
  71. esac
  72. }
  73. trap show_command_in_title_bar DEBUG
  74. ;;
  75. esac