From 2cc237267e3c70ed87d7725cc671c7e850be582f Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Sun, 21 Aug 2016 21:11:35 +0200 Subject: [PATCH 1/3] Improved Vagrant provider detection and support for parallels provider. Improved the detection of Vagrant provider. The previouse didn't correctly detect which provider was used. Added support for detecting the state of Parallels vagrant provider. --- fish_prompt.fish | 51 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index 8d1f9b3..c5dc97a 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -238,15 +238,24 @@ end function __bobthefish_prompt_vagrant -S -d 'Display Vagrant status' [ "$theme_display_vagrant" = 'yes' -a -f Vagrantfile ]; or return - if type -q VBoxManage - __bobthefish_prompt_vagrant_vbox - else if grep vmware_fusion Vagrantfile >/dev/null ^&1 - __bobthefish_prompt_vagrant_vmware + set provider (__bobthefish_vagrant_provider) + switch "$provider" + case 'virtualbox' + __bobthefish_prompt_vagrant_vbox + case 'vmware_fusion' + __bobthefish_prompt_vagrant_vmware + case 'parallels' + __bobthefish_prompt_vagrant_parallels end end -function __bobthefish_vagrant_ids -S -d 'List Vagrant machine ids' - for file in .vagrant/machines/**/id +function __bobthefish_vagrant_provider -S -d 'Get (first) Vagrant provider' + set -l first_provider (ls -1d .vagrant/machines/*/* | head -1) + echo $first_provider | sed -e 's/.*\/\(\w*\)/\1/' +end + +function __bobthefish_vagrant_ids -S -a provider -d 'List Vagrant machine ids' + for file in .vagrant/machines/*/$provider/id read id <$file echo $id end @@ -254,7 +263,7 @@ end function __bobthefish_prompt_vagrant_vbox -S -d 'Display VirtualBox Vagrant status' set -l vagrant_status - for id in (__bobthefish_vagrant_ids) + for id in (__bobthefish_vagrant_ids "virtualbox") set -l vm_status (VBoxManage showvminfo --machinereadable $id ^/dev/null | command grep 'VMState=' | tr -d '"' | cut -d '=' -f 2) switch "$vm_status" case 'running' @@ -280,7 +289,7 @@ end function __bobthefish_prompt_vagrant_vmware -S -d 'Display VMWare Vagrant status' set -l vagrant_status - for id in (__bobthefish_vagrant_ids) + for id in (__bobthefish_vagrant_ids "vmware_fusion") if [ (pgrep -f "$id") ] set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" else @@ -294,6 +303,32 @@ function __bobthefish_prompt_vagrant_vmware -S -d 'Display VMWare Vagrant status set_color normal end +function __bobthefish_prompt_vagrant_parallels -S -d 'Display Parallels Vagrant status' + set -l vagrant_status + for id in (__bobthefish_vagrant_ids "parallels") + set -l vm_status (prlctl list $id -o status ^/dev/null | command tail -1) + switch "$vm_status" + case 'running' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" + case 'stopped' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" + case 'paused' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" + case 'suspended' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" + case 'stopping' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_stopping_glyph" + case '' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_unknown_glyph" + end + end + [ -z "$vagrant_status" ]; and return + + __bobthefish_start_segment $__color_vagrant + echo -ns $vagrant_status ' ' + set_color normal +end + function __bobthefish_prompt_docker -S -d 'Show docker machine name' [ "$theme_display_docker_machine" = 'no' -o -z "$DOCKER_MACHINE_NAME" ]; and return __bobthefish_start_segment $__color_vagrant From 54ef10a8446dbf2a46bc1ed9c700b7e939f549ab Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Mon, 22 Aug 2016 08:22:04 +0200 Subject: [PATCH 2/3] Make provider a local var --- fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index c5dc97a..0c0ed1f 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -238,7 +238,7 @@ end function __bobthefish_prompt_vagrant -S -d 'Display Vagrant status' [ "$theme_display_vagrant" = 'yes' -a -f Vagrantfile ]; or return - set provider (__bobthefish_vagrant_provider) + set -l provider (__bobthefish_vagrant_provider) switch "$provider" case 'virtualbox' __bobthefish_prompt_vagrant_vbox From 525416cc195c4618bcb4498403eb2bb75676d959 Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Mon, 22 Aug 2016 21:35:20 +0200 Subject: [PATCH 3/3] Improved handling of Vagrantfiles with multiple providers --- fish_prompt.fish | 116 +++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index 0c0ed1f..c6c0795 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -238,47 +238,59 @@ end function __bobthefish_prompt_vagrant -S -d 'Display Vagrant status' [ "$theme_display_vagrant" = 'yes' -a -f Vagrantfile ]; or return - set -l provider (__bobthefish_vagrant_provider) - switch "$provider" - case 'virtualbox' - __bobthefish_prompt_vagrant_vbox - case 'vmware_fusion' - __bobthefish_prompt_vagrant_vmware - case 'parallels' - __bobthefish_prompt_vagrant_parallels + for machine in (__bobthefish_vagrant_machines) + set -l provider (__bobthefish_vagrant_provider $machine) + set -l id (__bobthefish_vagrant_id $machine $provider) + if [ ! -z "$id" ] + switch "$provider" + case 'virtualbox' + __bobthefish_prompt_vagrant_vbox $id + case 'vmware_fusion' + __bobthefish_prompt_vagrant_vmware $id + case 'parallels' + __bobthefish_prompt_vagrant_parallels $id + end + end + end +end + +function __bobthefish_vagrant_machines -S -d 'List all Vagrant machines' + for machine in .vagrant/machines/* + echo $machine | command sed -e 's/.*\/\(\w*\)/\1/' end end -function __bobthefish_vagrant_provider -S -d 'Get (first) Vagrant provider' - set -l first_provider (ls -1d .vagrant/machines/*/* | head -1) - echo $first_provider | sed -e 's/.*\/\(\w*\)/\1/' +function __bobthefish_vagrant_provider -S -a machine -d 'Get Vagrant provider for ' + for provider in .vagrant/machines/$machine/* + if [ -e $provider/id ] + echo $provider/id | command sed -ne 's/.vagrant\/machines\/'$machine'\/\(.*\)\/id/\1/p' + end + end end -function __bobthefish_vagrant_ids -S -a provider -d 'List Vagrant machine ids' - for file in .vagrant/machines/*/$provider/id - read id <$file +function __bobthefish_vagrant_id -S -a machine -a provider -d 'List Vagrant machine id' + if [ -n "$provider" ] + read id < .vagrant/machines/$machine/$provider/id echo $id end end -function __bobthefish_prompt_vagrant_vbox -S -d 'Display VirtualBox Vagrant status' +function __bobthefish_prompt_vagrant_vbox -S -a id -d 'Display VirtualBox Vagrant status' set -l vagrant_status - for id in (__bobthefish_vagrant_ids "virtualbox") - set -l vm_status (VBoxManage showvminfo --machinereadable $id ^/dev/null | command grep 'VMState=' | tr -d '"' | cut -d '=' -f 2) - switch "$vm_status" - case 'running' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" - case 'poweroff' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" - case 'aborted' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_aborted_glyph" - case 'saved' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" - case 'stopping' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_stopping_glyph" - case '' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_unknown_glyph" - end + set -l vm_status (VBoxManage showvminfo --machinereadable $id ^/dev/null | command grep 'VMState=' | tr -d '"' | cut -d '=' -f 2) + switch "$vm_status" + case 'running' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" + case 'poweroff' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" + case 'aborted' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_aborted_glyph" + case 'saved' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" + case 'stopping' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_stopping_glyph" + case '' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_unknown_glyph" end [ -z "$vagrant_status" ]; and return @@ -287,14 +299,12 @@ function __bobthefish_prompt_vagrant_vbox -S -d 'Display VirtualBox Vagrant stat set_color normal end -function __bobthefish_prompt_vagrant_vmware -S -d 'Display VMWare Vagrant status' +function __bobthefish_prompt_vagrant_vmware -S -a id -d 'Display VMWare Vagrant status' set -l vagrant_status - for id in (__bobthefish_vagrant_ids "vmware_fusion") - if [ (pgrep -f "$id") ] - set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" - else - set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" - end + if [ (pgrep -f "$id") ] + set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" + else + set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" end [ -z "$vagrant_status" ]; and return @@ -305,22 +315,20 @@ end function __bobthefish_prompt_vagrant_parallels -S -d 'Display Parallels Vagrant status' set -l vagrant_status - for id in (__bobthefish_vagrant_ids "parallels") - set -l vm_status (prlctl list $id -o status ^/dev/null | command tail -1) - switch "$vm_status" - case 'running' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" - case 'stopped' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" - case 'paused' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" - case 'suspended' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" - case 'stopping' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_stopping_glyph" - case '' - set vagrant_status "$vagrant_status$__bobthefish_vagrant_unknown_glyph" - end + set -l vm_status (prlctl list $id -o status ^/dev/null | command tail -1) + switch "$vm_status" + case 'running' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_running_glyph" + case 'stopped' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_poweroff_glyph" + case 'paused' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" + case 'suspended' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_saved_glyph" + case 'stopping' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_stopping_glyph" + case '' + set vagrant_status "$vagrant_status$__bobthefish_vagrant_unknown_glyph" end [ -z "$vagrant_status" ]; and return