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.

258 lines
7.7 KiB

3 years ago
  1. # vim:ft=zsh ts=2 sw=2 sts=2
  2. #
  3. # agnoster's Theme - https://gist.github.com/3712874
  4. # A Powerline-inspired theme for ZSH
  5. #
  6. # # README
  7. #
  8. # In order for this theme to render correctly, you will need a
  9. # [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
  10. # Make sure you have a recent version: the code points that Powerline
  11. # uses changed in 2012, and older versions will display incorrectly,
  12. # in confusing ways.
  13. #
  14. # In addition, I recommend the
  15. # [Solarized theme](https://github.com/altercation/solarized/) and, if you're
  16. # using it on Mac OS X, [iTerm 2](https://iterm2.com/) over Terminal.app -
  17. # it has significantly better color fidelity.
  18. #
  19. # If using with "light" variant of the Solarized color schema, set
  20. # SOLARIZED_THEME variable to "light". If you don't specify, we'll assume
  21. # you're using the "dark" variant.
  22. #
  23. # # Goals
  24. #
  25. # The aim of this theme is to only show you *relevant* information. Like most
  26. # prompts, it will only show git information when in a git working directory.
  27. # However, it goes a step further: everything from the current user and
  28. # hostname to whether the last call exited with an error to whether background
  29. # jobs are running in this shell will all be displayed automatically when
  30. # appropriate.
  31. ### Segment drawing
  32. # A few utility functions to make it easy and re-usable to draw segmented prompts
  33. CURRENT_BG='NONE'
  34. case ${SOLARIZED_THEME:-dark} in
  35. light) CURRENT_FG='white';;
  36. *) CURRENT_FG='black';;
  37. esac
  38. # Special Powerline characters
  39. () {
  40. local LC_ALL="" LC_CTYPE="en_US.UTF-8"
  41. # NOTE: This segment separator character is correct. In 2012, Powerline changed
  42. # the code points they use for their special characters. This is the new code point.
  43. # If this is not working for you, you probably have an old version of the
  44. # Powerline-patched fonts installed. Download and install the new version.
  45. # Do not submit PRs to change this unless you have reviewed the Powerline code point
  46. # history and have new information.
  47. # This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
  48. # what font the user is viewing this source code in. Do not replace the
  49. # escape sequence with a single literal character.
  50. # Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
  51. SEGMENT_SEPARATOR=$'\ue0b0'
  52. }
  53. # Begin a segment
  54. # Takes two arguments, background and foreground. Both can be omitted,
  55. # rendering default background/foreground.
  56. prompt_segment() {
  57. local bg fg
  58. [[ -n $1 ]] && bg="%K{$1}" || bg="%k"
  59. [[ -n $2 ]] && fg="%F{$2}" || fg="%f"
  60. if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
  61. echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
  62. else
  63. echo -n "%{$bg%}%{$fg%} "
  64. fi
  65. CURRENT_BG=$1
  66. [[ -n $3 ]] && echo -n $3
  67. }
  68. # End the prompt, closing any open segments
  69. prompt_end() {
  70. if [[ -n $CURRENT_BG ]]; then
  71. echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  72. else
  73. echo -n "%{%k%}"
  74. fi
  75. echo -n "%{%f%}"
  76. CURRENT_BG=''
  77. }
  78. ### Prompt components
  79. # Each component will draw itself, and hide itself if no information needs to be shown
  80. # Context: user@hostname (who am I and where am I)
  81. prompt_context() {
  82. if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
  83. prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
  84. fi
  85. }
  86. # Git: branch/detached head, dirty status
  87. prompt_git() {
  88. (( $+commands[git] )) || return
  89. if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
  90. return
  91. fi
  92. local PL_BRANCH_CHAR
  93. () {
  94. local LC_ALL="" LC_CTYPE="en_US.UTF-8"
  95. PL_BRANCH_CHAR=$'\ue0a0' # 
  96. }
  97. local ref dirty mode repo_path
  98. if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then
  99. repo_path=$(git rev-parse --git-dir 2>/dev/null)
  100. dirty=$(parse_git_dirty)
  101. ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
  102. if [[ -n $dirty ]]; then
  103. prompt_segment yellow black
  104. else
  105. prompt_segment green $CURRENT_FG
  106. fi
  107. if [[ -e "${repo_path}/BISECT_LOG" ]]; then
  108. mode=" <B>"
  109. elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
  110. mode=" >M<"
  111. elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
  112. mode=" >R>"
  113. fi
  114. setopt promptsubst
  115. autoload -Uz vcs_info
  116. zstyle ':vcs_info:*' enable git
  117. zstyle ':vcs_info:*' get-revision true
  118. zstyle ':vcs_info:*' check-for-changes true
  119. zstyle ':vcs_info:*' stagedstr '✚'
  120. zstyle ':vcs_info:*' unstagedstr '±'
  121. zstyle ':vcs_info:*' formats ' %u%c'
  122. zstyle ':vcs_info:*' actionformats ' %u%c'
  123. vcs_info
  124. echo -n "${${ref:gs/%/%%}/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
  125. fi
  126. }
  127. prompt_bzr() {
  128. (( $+commands[bzr] )) || return
  129. # Test if bzr repository in directory hierarchy
  130. local dir="$PWD"
  131. while [[ ! -d "$dir/.bzr" ]]; do
  132. [[ "$dir" = "/" ]] && return
  133. dir="${dir:h}"
  134. done
  135. local bzr_status status_mod status_all revision
  136. if bzr_status=$(bzr status 2>&1); then
  137. status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
  138. status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
  139. revision=${$(bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%}
  140. if [[ $status_mod -gt 0 ]] ; then
  141. prompt_segment yellow black "bzr@$revision ✚"
  142. else
  143. if [[ $status_all -gt 0 ]] ; then
  144. prompt_segment yellow black "bzr@$revision"
  145. else
  146. prompt_segment green black "bzr@$revision"
  147. fi
  148. fi
  149. fi
  150. }
  151. prompt_hg() {
  152. (( $+commands[hg] )) || return
  153. local rev st branch
  154. if $(hg id >/dev/null 2>&1); then
  155. if $(hg prompt >/dev/null 2>&1); then
  156. if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
  157. # if files are not added
  158. prompt_segment red white
  159. st='±'
  160. elif [[ -n $(hg prompt "{status|modified}") ]]; then
  161. # if any modification
  162. prompt_segment yellow black
  163. st='±'
  164. else
  165. # if working copy is clean
  166. prompt_segment green $CURRENT_FG
  167. fi
  168. echo -n ${$(hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st
  169. else
  170. st=""
  171. rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
  172. branch=$(hg id -b 2>/dev/null)
  173. if `hg st | grep -q "^\?"`; then
  174. prompt_segment red black
  175. st='±'
  176. elif `hg st | grep -q "^[MA]"`; then
  177. prompt_segment yellow black
  178. st='±'
  179. else
  180. prompt_segment green $CURRENT_FG
  181. fi
  182. echo -n "☿ ${rev:gs/%/%%}@${branch:gs/%/%%}" $st
  183. fi
  184. fi
  185. }
  186. # Dir: current working directory
  187. prompt_dir() {
  188. prompt_segment blue $CURRENT_FG '%~'
  189. }
  190. # Virtualenv: current working virtualenv
  191. prompt_virtualenv() {
  192. if [[ -n "$VIRTUAL_ENV" && -n "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then
  193. prompt_segment blue black "(${VIRTUAL_ENV:t:gs/%/%%})"
  194. fi
  195. }
  196. # Status:
  197. # - was there an error
  198. # - am I root
  199. # - are there background jobs?
  200. prompt_status() {
  201. local -a symbols
  202. [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
  203. [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
  204. [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
  205. [[ -n "$symbols" ]] && prompt_segment black default "$symbols"
  206. }
  207. #AWS Profile:
  208. # - display current AWS_PROFILE name
  209. # - displays yellow on red if profile name contains 'production' or
  210. # ends in '-prod'
  211. # - displays black on green otherwise
  212. prompt_aws() {
  213. [[ -z "$AWS_PROFILE" || "$SHOW_AWS_PROMPT" = false ]] && return
  214. case "$AWS_PROFILE" in
  215. *-prod|*production*) prompt_segment red yellow "AWS: ${AWS_PROFILE:gs/%/%%}" ;;
  216. *) prompt_segment green black "AWS: ${AWS_PROFILE:gs/%/%%}" ;;
  217. esac
  218. }
  219. ## Main prompt
  220. build_prompt() {
  221. RETVAL=$?
  222. prompt_status
  223. prompt_virtualenv
  224. prompt_aws
  225. prompt_context
  226. prompt_dir
  227. prompt_git
  228. prompt_bzr
  229. prompt_hg
  230. prompt_end
  231. }
  232. PROMPT='%{%f%b%k%}$(build_prompt) '