prompt.zsh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # prompt config
  2. export PR_OS_NAME=$(uname -s)
  3. export PR_OS_ARCH=$(uname -m)
  4. if [ -f /etc/debian_version ]; then
  5. PR_OS_NAME="Debian GNU/${PR_OS_NAME} $(</etc/debian_version)"
  6. [ -f /etc/debian_chroot ]\
  7. && PR_OS_NAME="$PR_OS_NAME [chroot: $(</etc/debian_version)]"
  8. fi
  9. [ "$TERM" = "screen" -a -n "$WINDOW" ] && PR_OS_PTY="screen/$WINDOW" || PR_OS_PTY=$(print -P %l)
  10. export PR_OS_PTY
  11. function preexec {
  12. binonly=(emacs mplayer lftp most more less rsu)
  13. args=(${=1})
  14. argsr=(${=2})
  15. if [[ $args[0] != $argsr[0] ]]; then
  16. args[0]=$argsr[0]
  17. fi
  18. [[ -n ${(M)binonly:#$args[0]} ]] && args=$args[0]
  19. if [ $UID = 0 ]; then
  20. [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "*$args"
  21. [ "$TERM" = "screen" ] && echo -ne "\033k*$args\033\\"
  22. else
  23. [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "$args"
  24. [ "$TERM" = "screen" ] && echo -ne "\033k$args\033\\"
  25. fi
  26. }
  27. function precmd {
  28. # function called before displaying prompt
  29. local TERMWIDTH
  30. (( TERMWIDTH = ${COLUMNS} - 1 ))
  31. # Truncate the path if it's too long.
  32. local promptsize=${#${(%):---(%m)-(%n)-(%D{%H:%M})-($PR_OS_PTY)-($PR_OS_NAME)-($PR_OS_ARCH)---}}
  33. PR_FILLBAR="\${(l.(($TERMWIDTH - $promptsize))..${PR_HBAR}.)}"
  34. if [ $UID = 0 ]; then
  35. [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "*$(print -P %~)"
  36. [ "$TERM" = "screen" ] && echo -ne "\033k*$(print -P %~)\033\\"
  37. else
  38. # if running konsole, setting current directory name in tab
  39. [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "$(print -P %~)"
  40. # if running screen, setting current directory name in caption/statusbar
  41. [ "$TERM" = "screen" ] && echo -ne "\033k$(print -P %~)\033\\"
  42. fi
  43. }
  44. myprompt() {
  45. setopt prompt_subst
  46. #enable colors
  47. autoload colors zsh/terminfo
  48. if [[ "$terminfo[colors]" -ge 8 ]]; then
  49. colors
  50. fi
  51. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  52. eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  53. eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  54. (( count = $count + 1 ))
  55. done
  56. PR_NO_COLOUR="%{$terminfo[sgr0]%}"
  57. typeset -A altchar
  58. set -A altchar ${(s..)terminfo[acsc]}
  59. PR_SET_CHARSET="%{$terminfo[enacs]%}"
  60. PR_SHIFT_IN="%{$terminfo[smacs]%}"
  61. PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
  62. PR_HBAR=${altchar[q]:--}
  63. PR_ULCORNER=${altchar[l]:--}
  64. PR_LLCORNER=${altchar[m]:--}
  65. PR_LRCORNER=${altchar[j]:--}
  66. PR_URCORNER=${altchar[k]:--}
  67. if [ "$TERM" = "dumb" ]; then
  68. PROMPT="-(%n@%m)-(%(!.%d.%~))->"
  69. else
  70. PROMPT='\
  71. $PR_SET_CHARSET\
  72. $PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_CYAN$PR_HBAR$PR_SHIFT_OUT(\
  73. $PR_WHITE%m$PR_CYAN\
  74. $PR_SHIFT_IN$PR_CYAN)$PR_HBAR$PR_SHIFT_OUT(\
  75. %(!.$PR_RED%n.$PR_LIGHT_GREEN%n)\
  76. $PR_SHIFT_IN$PR_CYAN)$PR_HBAR$PR_SHIFT_OUT(\
  77. $PR_WHITE%D{%H:%M}$PR_CYAN\
  78. $PR_SHIFT_IN$PR_CYAN)$PR_HBAR$PR_SHIFT_OUT(\
  79. $PR_WHITE$PR_OS_PTY$PR_CYAN\
  80. $PR_SHIFT_IN$PR_CYAN)$PR_HBAR$PR_SHIFT_OUT(\
  81. $PR_WHITE$PR_OS_NAME$PR_CYAN\
  82. $PR_SHIFT_IN$PR_CYAN)$PR_HBAR$PR_SHIFT_OUT(\
  83. $PR_WHITE$PR_OS_ARCH$PR_CYAN\
  84. $PR_SHIFT_IN$PR_CYAN)$PR_HBAR$PR_SHIFT_OUT\
  85. $PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_CYAN$PR_HBAR$PR_SHIFT_OUT\
  86. $PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_HBAR$PR_SHIFT_OUT\
  87. %1(j.{${PR_YELLOW}jobs$PR_CYAN:$PR_WHITE%j$PR_CYAN}$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT.)\
  88. %0(?..{${PR_RED}ret$PR_CYAN:$PR_WHITE%?$PR_CYAN}$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT)\
  89. ($PR_WHITE%(!.%d.%~)$PR_CYAN)$PR_SHIFT_IN$PR_HBAR$PR_LRCORNER$PR_SHIFT_OUT\
  90. >$PR_NO_COLOUR'
  91. fi
  92. }
  93. myprompt