]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
d7c76c3c965bfbf7a5108ac83698bc87a1c92b0d
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / vagrant-prompt / vagrant-prompt.plugin.zsh
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
18 function vagrant_prompt_info() {
19   local vm_states vm_state
20   if [[ -d .vagrant && -f Vagrantfile ]]; then
21     vm_states=(${(f)"$(vagrant status 2> /dev/null | sed -nE 's/^.*(saved|poweroff|running|not created) \([[:alnum:]_]+\)$/\1/p')"})
22     printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX
23     for vm_state in $vm_states; do
24       case "$vm_state" in
25         saved) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED ;;
26         running) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING ;;
27         poweroff) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF ;;
28         "not created") printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED ;;
29       esac
30     done
31     printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
32   fi
33 }