vagrant-prompt.plugin.zsh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. test -d .vagrant && test -f Vagrantfile
  19. if [[ "$?" == "0" ]]; then
  20. statuses=$(vagrant status 2> /dev/null | grep -P "\w+\s+[\w\s]+\s\(\w+\)")
  21. statuses=("${(f)statuses}")
  22. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX
  23. for vm_details in $statuses; do
  24. vm_state=$(echo $vm_details | grep -o -E "saved|poweroff|not created|running")
  25. if [[ "$vm_state" == "running" ]]; then
  26. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING
  27. elif [[ "$vm_state" == "saved" ]]; then
  28. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED
  29. elif [[ "$vm_state" == "not created" ]]; then
  30. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED
  31. elif [[ "$vm_state" == "poweroff" ]]; then
  32. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF
  33. fi
  34. done
  35. printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
  36. fi
  37. }