From 8898658a9a469c98d27eef93eae65259f2cf016c Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 25 Aug 2016 12:18:10 -0700 Subject: [PATCH] Speed up Vagrant status code by 10-15x. (Excluding whatever time is spent getting the status from the provider, of course. Can't do much with that) See #56 --- fish_prompt.fish | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index 96dafaa..66c329c 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -242,43 +242,24 @@ end function __bobthefish_prompt_vagrant -S -d 'Display Vagrant status' [ "$theme_display_vagrant" = 'yes' -a -f Vagrantfile ]; or return - for machine in (__bobthefish_vagrant_machines) - set -l provider (__bobthefish_vagrant_provider $machine) - set -l id (__bobthefish_vagrant_id $machine $provider) + + # .vagrant/machines/$machine/$provider/id + for file in .vagrant/machines/*/*/id + read -l id <$file + if [ ! -z "$id" ] - switch "$provider" - case 'virtualbox' + switch "$file" + case '*/virtualbox/id' __bobthefish_prompt_vagrant_vbox $id - case 'vmware_fusion' + case '*/vmware_fusion/id' __bobthefish_prompt_vagrant_vmware $id - case 'parallels' + case '*/parallels/id' __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 -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_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 -a id -d 'Display VirtualBox Vagrant status' set -l vagrant_status set -l vm_status (VBoxManage showvminfo --machinereadable $id ^/dev/null | command grep 'VMState=' | tr -d '"' | cut -d '=' -f 2)