All of my important config files
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.

284 lines
8.2 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. ##### prezto/prompt ######
  32. #
  33. # Prompt setup function commonly used by prompt themes.
  34. #
  35. # Authors:
  36. # Sorin Ionescu <sorin.ionescu@gmail.com>
  37. #
  38. prompt_pwd() {
  39. setopt localoptions extendedglob
  40. local current_pwd="${PWD/#$HOME/~}"
  41. local ret_directory
  42. if [[ "$current_pwd" == (#m)[/~] ]]; then
  43. ret_directory="$MATCH"
  44. unset MATCH
  45. elif zstyle -m ':prezto:module:prompt' pwd-length 'full'; then
  46. ret_directory=${PWD}
  47. elif zstyle -m ':prezto:module:prompt' pwd-length 'long'; then
  48. ret_directory=${current_pwd}
  49. else
  50. ret_directory="${${${${(@j:/:M)${(@s:/:)current_pwd}##.#?}:h}%/}//\%/%%}/${${current_pwd:t}//\%/%%}"
  51. fi
  52. unset current_pwd
  53. print "$ret_directory"
  54. }
  55. ################################
  56. ### Segment drawing
  57. # A few utility functions to make it easy and re-usable to draw segmented prompts
  58. CURRENT_BG='NONE'
  59. case ${SOLARIZED_THEME:-dark} in
  60. light) CURRENT_FG='white';;
  61. *) CURRENT_FG='black';;
  62. esac
  63. # Special Powerline characters
  64. () {
  65. local LC_ALL="" LC_CTYPE="en_US.UTF-8"
  66. # NOTE: This segment separator character is correct. In 2012, Powerline changed
  67. # the code points they use for their special characters. This is the new code point.
  68. # If this is not working for you, you probably have an old version of the
  69. # Powerline-patched fonts installed. Download and install the new version.
  70. # Do not submit PRs to change this unless you have reviewed the Powerline code point
  71. # history and have new information.
  72. # This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
  73. # what font the user is viewing this source code in. Do not replace the
  74. # escape sequence with a single literal character.
  75. # Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
  76. SEGMENT_SEPARATOR=$'\ue0b0'
  77. }
  78. # Begin a segment
  79. # Takes two arguments, background and foreground. Both can be omitted,
  80. # rendering default background/foreground.
  81. prompt_segment() {
  82. local bg fg
  83. [[ -n $1 ]] && bg="%K{$1}" || bg="%k"
  84. [[ -n $2 ]] && fg="%F{$2}" || fg="%f"
  85. if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
  86. echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
  87. else
  88. echo -n "%{$bg%}%{$fg%} "
  89. fi
  90. CURRENT_BG=$1
  91. [[ -n $3 ]] && echo -n $3
  92. }
  93. # End the prompt, closing any open segments
  94. prompt_end() {
  95. if [[ -n $CURRENT_BG ]]; then
  96. echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  97. else
  98. echo -n "%{%k%}"
  99. fi
  100. echo -n "%{%f%}"
  101. CURRENT_BG=''
  102. }
  103. ### Prompt components
  104. # Each component will draw itself, and hide itself if no information needs to be shown
  105. # Context: user@hostname (who am I and where am I)
  106. prompt_context() {
  107. if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
  108. prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
  109. fi
  110. }
  111. # Git: branch/detached head, dirty status
  112. prompt_git() {
  113. (( $+commands[git] )) || return
  114. if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
  115. return
  116. fi
  117. local PL_BRANCH_CHAR
  118. () {
  119. local LC_ALL="" LC_CTYPE="en_US.UTF-8"
  120. PL_BRANCH_CHAR=$'\ue0a0' # 
  121. }
  122. local ref dirty mode repo_path
  123. if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
  124. repo_path=$(git rev-parse --git-dir 2>/dev/null)
  125. dirty=$(parse_git_dirty)
  126. ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
  127. if [[ -n $dirty ]]; then
  128. prompt_segment yellow black
  129. else
  130. prompt_segment green $CURRENT_FG
  131. fi
  132. if [[ -e "${repo_path}/BISECT_LOG" ]]; then
  133. mode=" <B>"
  134. elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
  135. mode=" >M<"
  136. elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
  137. mode=" >R>"
  138. fi
  139. setopt promptsubst
  140. autoload -Uz vcs_info
  141. zstyle ':vcs_info:*' enable git
  142. zstyle ':vcs_info:*' get-revision true
  143. zstyle ':vcs_info:*' check-for-changes true
  144. zstyle ':vcs_info:*' stagedstr '✚'
  145. zstyle ':vcs_info:*' unstagedstr '●'
  146. zstyle ':vcs_info:*' formats ' %u%c'
  147. zstyle ':vcs_info:*' actionformats ' %u%c'
  148. vcs_info
  149. echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
  150. fi
  151. }
  152. prompt_bzr() {
  153. (( $+commands[bzr] )) || return
  154. if (bzr status >/dev/null 2>&1); then
  155. status_mod=`bzr status | head -n1 | grep "modified" | wc -m`
  156. status_all=`bzr status | head -n1 | wc -m`
  157. revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
  158. if [[ $status_mod -gt 0 ]] ; then
  159. prompt_segment yellow black
  160. echo -n "bzr@"$revision "✚ "
  161. else
  162. if [[ $status_all -gt 0 ]] ; then
  163. prompt_segment yellow black
  164. echo -n "bzr@"$revision
  165. else
  166. prompt_segment green black
  167. echo -n "bzr@"$revision
  168. fi
  169. fi
  170. fi
  171. }
  172. prompt_hg() {
  173. (( $+commands[hg] )) || return
  174. local rev st branch
  175. if $(hg id >/dev/null 2>&1); then
  176. if $(hg prompt >/dev/null 2>&1); then
  177. if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
  178. # if files are not added
  179. prompt_segment red white
  180. st='±'
  181. elif [[ -n $(hg prompt "{status|modified}") ]]; then
  182. # if any modification
  183. prompt_segment yellow black
  184. st='±'
  185. else
  186. # if working copy is clean
  187. prompt_segment green $CURRENT_FG
  188. fi
  189. echo -n $(hg prompt "☿ {rev}@{branch}") $st
  190. else
  191. st=""
  192. rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
  193. branch=$(hg id -b 2>/dev/null)
  194. if `hg st | grep -q "^\?"`; then
  195. prompt_segment red black
  196. st='±'
  197. elif `hg st | grep -q "^[MA]"`; then
  198. prompt_segment yellow black
  199. st='±'
  200. else
  201. prompt_segment green $CURRENT_FG
  202. fi
  203. echo -n "☿ $rev@$branch" $st
  204. fi
  205. fi
  206. }
  207. # Dir: current working directory
  208. prompt_dir() {
  209. prompt_segment blue $CURRENT_FG '%~'
  210. }
  211. # Virtualenv: current working virtualenv
  212. prompt_virtualenv() {
  213. local virtualenv_path="$VIRTUAL_ENV"
  214. if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
  215. prompt_segment blue black "(`basename $virtualenv_path`)"
  216. fi
  217. }
  218. # Status:
  219. # - was there an error
  220. # - am I root
  221. # - are there background jobs?
  222. prompt_status() {
  223. local -a symbols
  224. [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘ %?"
  225. [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
  226. [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
  227. [[ -n "$symbols" ]] && prompt_segment black default "$symbols"
  228. }
  229. #AWS Profile:
  230. # - display current AWS_PROFILE name
  231. # - displays yellow on red if profile name contains 'production' or
  232. # ends in '-prod'
  233. # - displays black on green otherwise
  234. prompt_aws() {
  235. [[ -z "$AWS_PROFILE" ]] && return
  236. case "$AWS_PROFILE" in
  237. *-prod|*production*) prompt_segment red yellow "AWS: $AWS_PROFILE" ;;
  238. *) prompt_segment green black "AWS: $AWS_PROFILE" ;;
  239. esac
  240. }
  241. ## Main prompt
  242. build_prompt() {
  243. RETVAL=$?
  244. prompt_status
  245. prompt_virtualenv
  246. prompt_context
  247. prompt_dir
  248. prompt_git
  249. prompt_end
  250. }
  251. PROMPT='%{%f%b%k%}$(build_prompt) '