4c9fc2634b3125e2b253de11b5208ccbfcfa8232
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
vagrant-prompt: replace `grep -P` call with sed and clean up
Fixes #9207
Diff
1diff --git a/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh b/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
2index 28bf31f9143ca0a26bfbdfe152fc0390da37cde5..d7c76c3c965bfbf7a5108ac83698bc87a1c92b0d 100644
3--- a/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
4+++ b/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
5@@ -16,22 +16,17 @@
6 # ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED="%{$fg_no_bold[white]%}○"
7
8 function vagrant_prompt_info() {
9- test -d .vagrant && test -f Vagrantfile
10- if [[ "$?" == "0" ]]; then
11- statuses=$(vagrant status 2> /dev/null | grep -P "\w+\s+[\w\s]+\s\(\w+\)")
12- statuses=("${(f)statuses}")
13+ local vm_states vm_state
14+ if [[ -d .vagrant && -f Vagrantfile ]]; then
15+ vm_states=(${(f)"$(vagrant status 2> /dev/null | sed -nE 's/^.*(saved|poweroff|running|not created) \([[:alnum:]_]+\)$/\1/p')"})
16 printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX
17- for vm_details in $statuses; do
18- vm_state=$(echo $vm_details | grep -o -E "saved|poweroff|not created|running")
19- if [[ "$vm_state" == "running" ]]; then
20- printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING
21- elif [[ "$vm_state" == "saved" ]]; then
22- printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED
23- elif [[ "$vm_state" == "not created" ]]; then
24- printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED
25- elif [[ "$vm_state" == "poweroff" ]]; then
26- printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF
27- fi
28+ for vm_state in $vm_states; do
29+ case "$vm_state" in
30+ saved) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED ;;
31+ running) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING ;;
32+ poweroff) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF ;;
33+ "not created") printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED ;;
34+ esac
35 done
36 printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
37 fi