my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.9 KiB

3 years ago
  1. function theme_precmd {
  2. local TERMWIDTH=$(( COLUMNS - ${ZLE_RPROMPT_INDENT:-1} ))
  3. PR_FILLBAR=""
  4. PR_PWDLEN=""
  5. local promptsize=${#${(%):---(%n@%m:%l)---()--}}
  6. local rubypromptsize=${#${(%)$(ruby_prompt_info)}}
  7. local pwdsize=${#${(%):-%~}}
  8. # Truncate the path if it's too long.
  9. if (( promptsize + rubypromptsize + pwdsize > TERMWIDTH )); then
  10. (( PR_PWDLEN = TERMWIDTH - promptsize ))
  11. elif [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
  12. PR_FILLBAR="\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize) ))::${PR_HBAR}:)}"
  13. else
  14. PR_FILLBAR="${PR_SHIFT_IN}\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize) ))::${altchar[q]:--}:)}${PR_SHIFT_OUT}"
  15. fi
  16. }
  17. function theme_preexec {
  18. setopt local_options extended_glob
  19. if [[ "$TERM" = "screen" ]]; then
  20. local CMD=${1[(wr)^(*=*|sudo|-*)]}
  21. echo -n "\ek$CMD\e\\"
  22. fi
  23. }
  24. autoload -U add-zsh-hook
  25. add-zsh-hook precmd theme_precmd
  26. add-zsh-hook preexec theme_preexec
  27. # Set the prompt
  28. # Need this so the prompt will work.
  29. setopt prompt_subst
  30. # See if we can use colors.
  31. autoload zsh/terminfo
  32. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do
  33. typeset -g PR_$color="%{$terminfo[bold]$fg[${(L)color}]%}"
  34. typeset -g PR_LIGHT_$color="%{$fg[${(L)color}]%}"
  35. done
  36. PR_NO_COLOUR="%{$terminfo[sgr0]%}"
  37. # Modify Git prompt
  38. ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[green]%}"
  39. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
  40. ZSH_THEME_GIT_PROMPT_DIRTY=""
  41. ZSH_THEME_GIT_PROMPT_CLEAN=""
  42. ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} %{%G✚%}"
  43. ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} %{%G✹%}"
  44. ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} %{%G✖%}"
  45. ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} %{%G➜%}"
  46. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} %{%G═%}"
  47. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} %{%G✭%}"
  48. # Use extended characters to look nicer if supported.
  49. if [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
  50. PR_SET_CHARSET=""
  51. PR_HBAR="─"
  52. PR_ULCORNER="┌"
  53. PR_LLCORNER="└"
  54. PR_LRCORNER="┘"
  55. PR_URCORNER="┐"
  56. else
  57. typeset -g -A altchar
  58. set -A altchar ${(s..)terminfo[acsc]}
  59. # Some stuff to help us draw nice lines
  60. PR_SET_CHARSET="%{$terminfo[enacs]%}"
  61. PR_SHIFT_IN="%{$terminfo[smacs]%}"
  62. PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
  63. PR_HBAR="${PR_SHIFT_IN}${altchar[q]:--}${PR_SHIFT_OUT}"
  64. PR_ULCORNER="${PR_SHIFT_IN}${altchar[l]:--}${PR_SHIFT_OUT}"
  65. PR_LLCORNER="${PR_SHIFT_IN}${altchar[m]:--}${PR_SHIFT_OUT}"
  66. PR_LRCORNER="${PR_SHIFT_IN}${altchar[j]:--}${PR_SHIFT_OUT}"
  67. PR_URCORNER="${PR_SHIFT_IN}${altchar[k]:--}${PR_SHIFT_OUT}"
  68. fi
  69. # Decide if we need to set titlebar text.
  70. case $TERM in
  71. xterm*)
  72. PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
  73. ;;
  74. screen)
  75. PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
  76. ;;
  77. *)
  78. PR_TITLEBAR=""
  79. ;;
  80. esac
  81. # Decide whether to set a screen title
  82. if [[ "$TERM" = "screen" ]]; then
  83. PR_STITLE=$'%{\ekzsh\e\\%}'
  84. else
  85. PR_STITLE=""
  86. fi
  87. # Finally, the prompt.
  88. PROMPT='${PR_SET_CHARSET}${PR_STITLE}${(e)PR_TITLEBAR}\
  89. ${PR_CYAN}${PR_ULCORNER}${PR_HBAR}${PR_GREY}(\
  90. ${PR_GREEN}%${PR_PWDLEN}<...<%~%<<\
  91. ${PR_GREY})$(ruby_prompt_info)${PR_CYAN}${PR_HBAR}${PR_HBAR}${(e)PR_FILLBAR}${PR_HBAR}${PR_GREY}(\
  92. ${PR_CYAN}%(!.%SROOT%s.%n)${PR_GREY}@${PR_GREEN}%m:%l\
  93. ${PR_GREY})${PR_CYAN}${PR_HBAR}${PR_URCORNER}\
  94. ${PR_CYAN}${PR_LLCORNER}${PR_BLUE}${PR_HBAR}(\
  95. ${PR_YELLOW}%D{%H:%M:%S}\
  96. ${PR_LIGHT_BLUE}%{$reset_color%}$(git_prompt_info)$(git_prompt_status)${PR_BLUE})${PR_CYAN}${PR_HBAR}\
  97. ${PR_HBAR}\
  98. >${PR_NO_COLOUR} '
  99. # display exitcode on the right when > 0
  100. return_code="%(?..%{$fg[red]%}%? ↵ %{$reset_color%})"
  101. RPROMPT=' $return_code${PR_CYAN}${PR_HBAR}${PR_BLUE}${PR_HBAR}\
  102. (${PR_YELLOW}%D{%a,%b%d}${PR_BLUE})${PR_HBAR}${PR_CYAN}${PR_LRCORNER}${PR_NO_COLOUR}'
  103. PS2='${PR_CYAN}${PR_HBAR}\
  104. ${PR_BLUE}${PR_HBAR}(\
  105. ${PR_LIGHT_GREEN}%_${PR_BLUE})${PR_HBAR}\
  106. ${PR_CYAN}${PR_HBAR}${PR_NO_COLOUR} '