vagrant-prompt.plugin.zsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. # vim:ft=zsh ts=2 sw=2 sts=2
  2. #
  3. # To display Vagrant infos on your prompt add the vagrant_prompt_info to the
  4. # $PROMPT variable in your theme. Example:
  5. #
  6. # PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $(vagrant_prompt_info)$(svn_prompt_info)$(git_prompt_info)%(!.#.$) '
  7. #
  8. # `vagrant_prompt_info` makes use of some custom variables. This is an example
  9. # definition:
  10. #
  11. # ZSH_THEME_VAGRANT_PROMPT_PREFIX="%{$fg_bold[blue]%}["
  12. # ZSH_THEME_VAGRANT_PROMPT_SUFFIX="%{$fg_bold[blue]%}]%{$reset_color%} "
  13. # ZSH_THEME_VAGRANT_PROMPT_RUNNING="%{$fg_no_bold[green]%}●"
  14. # ZSH_THEME_VAGRANT_PROMPT_POWEROFF="%{$fg_no_bold[red]%}●"
  15. # ZSH_THEME_VAGRANT_PROMPT_SUSPENDED="%{$fg_no_bold[yellow]%}●"
  16. # ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED="%{$fg_no_bold[white]%}○"
  17. function vagrant_prompt_info() {
  18. local vm_states vm_state
  19. if [[ -d .vagrant && -f Vagrantfile ]]; then
  20. vm_states=(${(f)"$(vagrant status 2> /dev/null | sed -nE 's/^.*(saved|poweroff|running|not created) \([[:alnum:]_]+\)$/\1/p')"})
  21. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX
  22. for vm_state in $vm_states; do
  23. case "$vm_state" in
  24. saved) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED ;;
  25. running) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING ;;
  26. poweroff) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF ;;
  27. "not created") printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED ;;
  28. esac
  29. done
  30. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
  31. fi
  32. }