pygmalion-virtualenv.zsh-theme 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Yay! High voltage and arrows!
  2. function _virtualenv_prompt_info {
  3. if [[ -n "$(whence virtualenv_prompt_info)" ]]; then
  4. if [ -n "$(whence pyenv_prompt_info)" ]; then
  5. if [ "$1" = "inline" ]; then
  6. ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX=%{$fg[blue]%}"::%{$fg[red]%}"
  7. ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX=""
  8. virtualenv_prompt_info
  9. fi
  10. [ "$(pyenv_prompt_info)" = "${PYENV_PROMPT_DEFAULT_VERSION}" ] && virtualenv_prompt_info
  11. else
  12. virtualenv_prompt_info
  13. fi
  14. fi
  15. }
  16. prompt_setup_pygmalion(){
  17. ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
  18. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
  19. ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
  20. ZSH_THEME_GIT_PROMPT_CLEAN=""
  21. base_prompt='$(_virtualenv_prompt_info)%{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}'
  22. post_prompt='%{$fg[cyan]%}⇒%{$reset_color%} '
  23. base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
  24. post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
  25. autoload -U add-zsh-hook
  26. add-zsh-hook precmd prompt_pygmalion_precmd
  27. }
  28. prompt_pygmalion_precmd(){
  29. local gitinfo=$(git_prompt_info)
  30. local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g")
  31. local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
  32. local prompt_length=${#exp_nocolor}
  33. local nl=""
  34. if [[ $prompt_length -gt 40 ]]; then
  35. nl=$'\n%{\r%}';
  36. fi
  37. PROMPT="$base_prompt$gitinfo$nl$post_prompt"
  38. }
  39. prompt_setup_pygmalion