diff options
| author | Marc Cornellà <marc.cornella@live.com> | 2019-05-08 20:40:36 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-08 20:40:36 +0200 | 
| commit | 0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534 (patch) | |
| tree | 946d9f8b758ebdd63da96152ca56b154c99068da /plugins/vagrant-prompt | |
| parent | afb028763cf40fc339e49011b2cba124dc108fcb (diff) | |
| parent | ebc700be9b2fa7ae770a644093a5c46a8e323726 (diff) | |
| download | zsh-0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534.tar.gz zsh-0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534.tar.bz2 zsh-0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534.zip | |
Merge branch 'master' into master
Diffstat (limited to 'plugins/vagrant-prompt')
| -rw-r--r-- | plugins/vagrant-prompt/README.md | 6 | ||||
| -rw-r--r-- | plugins/vagrant-prompt/vagrant-prompt.plugin.zsh | 38 | 
2 files changed, 44 insertions, 0 deletions
| diff --git a/plugins/vagrant-prompt/README.md b/plugins/vagrant-prompt/README.md new file mode 100644 index 000000000..c5bc55d17 --- /dev/null +++ b/plugins/vagrant-prompt/README.md @@ -0,0 +1,6 @@ +This plugin prompts the status of the Vagrant VMs. It supports single-host and +multi-host configurations as well. + +Look inside the source for documentation about custom variables.  + +Alberto Re <alberto.re@gmail.com> diff --git a/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh b/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh new file mode 100644 index 000000000..28bf31f91 --- /dev/null +++ b/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh @@ -0,0 +1,38 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 +# +# To display Vagrant infos on your prompt add the vagrant_prompt_info to the +# $PROMPT variable in your theme. Example: +# +# PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $(vagrant_prompt_info)$(svn_prompt_info)$(git_prompt_info)%(!.#.$) ' +# +# `vagrant_prompt_info` makes use of some custom variables. This is an example +# definition: +# +# ZSH_THEME_VAGRANT_PROMPT_PREFIX="%{$fg_bold[blue]%}[" +# ZSH_THEME_VAGRANT_PROMPT_SUFFIX="%{$fg_bold[blue]%}]%{$reset_color%} " +# ZSH_THEME_VAGRANT_PROMPT_RUNNING="%{$fg_no_bold[green]%}●" +# ZSH_THEME_VAGRANT_PROMPT_POWEROFF="%{$fg_no_bold[red]%}●" +# ZSH_THEME_VAGRANT_PROMPT_SUSPENDED="%{$fg_no_bold[yellow]%}●" +# ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED="%{$fg_no_bold[white]%}○" + +function vagrant_prompt_info() { +  test -d .vagrant && test -f Vagrantfile +  if [[ "$?" == "0" ]]; then +    statuses=$(vagrant status 2> /dev/null | grep -P "\w+\s+[\w\s]+\s\(\w+\)") +    statuses=("${(f)statuses}") +    printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX +    for vm_details in $statuses; do +      vm_state=$(echo $vm_details | grep -o -E "saved|poweroff|not created|running") +      if [[ "$vm_state" == "running" ]]; then +        printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING +      elif [[ "$vm_state" == "saved" ]]; then +        printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED +      elif [[ "$vm_state" == "not created" ]]; then +        printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED +      elif [[ "$vm_state" == "poweroff" ]]; then +        printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF +      fi +    done +    printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX +  fi +} | 
