summaryrefslogtreecommitdiff
path: root/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2020-08-28 23:50:05 +0200
committerMarc Cornellà <marc.cornella@live.com>2020-08-28 23:50:37 +0200
commit4c9fc2634b3125e2b253de11b5208ccbfcfa8232 (patch)
tree4ab2bc9feb3562696e5cbd4e3b5b24c07ebd133e /plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
parent8d08f1634a7b9782e3722ce770e8630f569afe3f (diff)
downloadzsh-4c9fc2634b3125e2b253de11b5208ccbfcfa8232.tar.gz
zsh-4c9fc2634b3125e2b253de11b5208ccbfcfa8232.tar.bz2
zsh-4c9fc2634b3125e2b253de11b5208ccbfcfa8232.zip
vagrant-prompt: replace `grep -P` call with sed and clean up
Fixes #9207
Diffstat (limited to 'plugins/vagrant-prompt/vagrant-prompt.plugin.zsh')
-rw-r--r--plugins/vagrant-prompt/vagrant-prompt.plugin.zsh25
1 files changed, 10 insertions, 15 deletions
diff --git a/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh b/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
index 28bf31f91..d7c76c3c9 100644
--- a/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
+++ b/plugins/vagrant-prompt/vagrant-prompt.plugin.zsh
@@ -16,22 +16,17 @@
# 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}")
+ local vm_states vm_state
+ if [[ -d .vagrant && -f Vagrantfile ]]; then
+ vm_states=(${(f)"$(vagrant status 2> /dev/null | sed -nE 's/^.*(saved|poweroff|running|not created) \([[:alnum:]_]+\)$/\1/p')"})
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
+ for vm_state in $vm_states; do
+ case "$vm_state" in
+ saved) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED ;;
+ running) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING ;;
+ poweroff) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF ;;
+ "not created") printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED ;;
+ esac
done
printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
fi