thm.zsh-theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # thm-zshtheme
  2. function virtualenv_info {
  3. [ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
  4. }
  5. function prompt_char {
  6. git branch >/dev/null 2>/dev/null && echo "$GIT_PROMPT_SYMBOL" && return
  7. hg root >/dev/null 2>/dev/null && echo "$MER_PROMPT_SYMBOL" && return
  8. svn info >/dev/null 2>/dev/null && echo "$SVN_PROMPT_SYMBOL" && return
  9. echo '◇'%{$reset_color%}
  10. }
  11. # You can set your computer name in the ~/.box-name file if you want.
  12. function box_name {
  13. [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
  14. }
  15. #setopt promptsubst
  16. autoload -U colors && colors # Enable colors in prompt
  17. # Modify the colors and symbols in these variables as desired.
  18. MER_PROMPT_SYMBOL="%{$FG[177]%}☿" #Mercurial
  19. SVN_PROMPT_SYMBOL="%{$FG[170]%}∮" #SVN
  20. GIT_PROMPT_SYMBOL="%{$FG[162]%}±" #Git
  21. GIT_PROMPT_PREFIX="%{$fg[black]%} %{$reset_color%}"
  22. GIT_PROMPT_SUFFIX="%{$fg[black]%} %{$reset_color%}"
  23. GIT_PROMPT_AHEAD="%{$fg[yellow]%}⬆%{$reset_color%} "
  24. GIT_PROMPT_BEHIND="%{$fg[yellow]%}⬇%{$reset_color%} "
  25. GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"
  26. GIT_PROMPT_UNTRACKED="%{$fg[yellow]%}✭ "
  27. GIT_PROMPT_MODIFIED="%{$fg[cyan]%}▲ "
  28. GIT_PROMPT_ADDED="%{$fg[green]%}✚%{$reset_color%} "
  29. # Git prompt configuration
  30. GIT_PROMPT_DIRTY="%{$fg[red]%} ✘✘✘"
  31. GIT_PROMPT_CLEAN="%{$fg[green]%} ✔"
  32. # Show Git branch/tag, or name-rev if on detached head
  33. function parse_git_branch() {
  34. (git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
  35. }
  36. # Show different symbols as appropriate for various Git repository states
  37. function parse_git_state() {
  38. # Compose this value via multiple conditional appends.
  39. local GIT_STATE=""
  40. local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
  41. if [ "$NUM_AHEAD" -gt 0 ]; then
  42. GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
  43. fi
  44. local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
  45. if [ "$NUM_BEHIND" -gt 0 ]; then
  46. GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
  47. fi
  48. local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
  49. if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
  50. GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
  51. fi
  52. if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
  53. GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
  54. fi
  55. if ! git diff --quiet 2> /dev/null; then
  56. GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
  57. fi
  58. if ! git diff --cached --quiet 2> /dev/null; then
  59. GIT_STATE=$GIT_STATE$GIT_PROMPT_ADDED
  60. fi
  61. if [[ -n $GIT_STATE ]]; then
  62. echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
  63. fi
  64. }
  65. git_dirty() {
  66. if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
  67. echo "$GIT_PROMPT_DIRTY"
  68. else
  69. echo "$GIT_PROMPT_CLEAN"
  70. fi
  71. }
  72. function git_prompt_string() {
  73. local git_where="$(parse_git_branch)"
  74. [ -n "$git_where" ] && echo "%{$FG[239]%}\ue0a0 %{$fg[white]%}${git_where#(refs/heads/|tags/)}$(git_dirty)$(parse_git_state)"
  75. }
  76. local rvm_ruby='$(rvm-prompt i v g)%{$reset_color%}'
  77. function current_pwd {
  78. echo $(pwd | sed -e "s,^$HOME,~,")
  79. }
  80. PROMPT='
  81. %{$fg[green]%}╭──%{$fg[yellow]%} $(current_pwd)%{$reset_color%} $(git_prompt_string)%{$reset_color%}
  82. %{$fg[green]%}╰────▶ %{$reset_color%}'
  83. export SPROMPT="Correct $fg[red]%R$reset_color to $fg[green]%r$reset_color [(y)es (n)o (a)bort (e)dit]? "