af-magic.zsh-theme 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # af-magic.zsh-theme
  2. #
  3. # Author: Andy Fleming
  4. # URL: http://andyfleming.com/
  5. # dashed separator size
  6. function afmagic_dashes {
  7. # check either virtualenv or condaenv variables
  8. local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}"
  9. local python_env="${python_env_dir##*/}"
  10. # if there is a python virtual environment and it is displayed in
  11. # the prompt, account for it when returning the number of dashes
  12. if [[ -n "$python_env" && "$PS1" = *\(${python_env}\)* ]]; then
  13. echo $(( COLUMNS - ${#python_env} - 3 ))
  14. elif [[ -n "$VIRTUAL_ENV_PROMPT" && "$PS1" = *${VIRTUAL_ENV_PROMPT}* ]]; then
  15. echo $(( COLUMNS - ${#VIRTUAL_ENV_PROMPT} ))
  16. else
  17. echo $COLUMNS
  18. fi
  19. }
  20. # primary prompt: dashed separator, directory and vcs info
  21. PS1="${FG[237]}\${(l.\$(afmagic_dashes)..-.)}%{$reset_color%}
  22. ${FG[032]}%~\$(git_prompt_info)\$(hg_prompt_info) ${FG[105]}%(!.#.»)%{$reset_color%} "
  23. PS2="%{$fg[red]%}\ %{$reset_color%}"
  24. # right prompt: return code, virtualenv and context (user@host)
  25. RPS1="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
  26. if (( $+functions[virtualenv_prompt_info] )); then
  27. RPS1+='$(virtualenv_prompt_info)'
  28. fi
  29. RPS1+=" ${FG[237]}%n@%m%{$reset_color%}"
  30. # git settings
  31. ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[075]}(${FG[078]}"
  32. ZSH_THEME_GIT_PROMPT_CLEAN=""
  33. ZSH_THEME_GIT_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}"
  34. ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}"
  35. # hg settings
  36. ZSH_THEME_HG_PROMPT_PREFIX=" ${FG[075]}(${FG[078]}"
  37. ZSH_THEME_HG_PROMPT_CLEAN=""
  38. ZSH_THEME_HG_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}"
  39. ZSH_THEME_HG_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}"
  40. # virtualenv settings
  41. ZSH_THEME_VIRTUALENV_PREFIX=" ${FG[075]}["
  42. ZSH_THEME_VIRTUALENV_SUFFIX="]%{$reset_color%}"