9d6b6c5ce161280e52df3a33d584318d6dbc0bd9

Author
T0mK0 <T0mK0@users.noreply.github.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

speed up chruby plugin by eliminating(as much as possible) calls to brew (#6080)

* speed up chruby plugin by eliminating(as much as possible) calls to brew

* speed up aws plugin by eliminating(as much as possible) calls to brew

Diff

 1diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh
 2index d31052f8300082f0d7ed5a47e59a2cf1454288d0..6a0e04add6e2454390dd89d4bb064de7f1e2ca72 100644
 3--- a/plugins/aws/aws.plugin.zsh
 4+++ b/plugins/aws/aws.plugin.zsh
 5@@ -1,9 +1,24 @@
 6 _homebrew-installed() {
 7   type brew &> /dev/null
 8+  _xit=$?
 9+  if [ $_xit -eq 0 ];then
10+        # ok , we have brew installed
11+        # speculatively we check default brew prefix
12+        if [ -h  /usr/local/opt/awscli ];then
13+                _brew_prefix="/usr/local/opt/awscli"
14+        else
15+                # ok , it is not default prefix
16+                # this call to brew is expensive ( about 400 ms ), so at least let's make it only once
17+                _brew_prefix=$(brew --prefix awscli)
18+        fi
19+        return 0
20+   else
21+        return $_xit
22+   fi
23 }
24 
25 _awscli-homebrew-installed() {
26-  brew list awscli &> /dev/null
27+  [ -r $_brew_prefix/libexec/bin/aws_zsh_completer.sh ] &> /dev/null
28 }
29 
30 export AWS_HOME=~/.aws
31@@ -28,7 +43,7 @@ function aws_profiles {
32 compctl -K aws_profiles asp
33 
34 if _homebrew-installed && _awscli-homebrew-installed ; then
35-  _aws_zsh_completer_path=$(brew --prefix awscli)/libexec/bin/aws_zsh_completer.sh
36+  _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
37 else
38   _aws_zsh_completer_path=$(which aws_zsh_completer.sh)
39 fi
40diff --git a/plugins/chruby/chruby.plugin.zsh b/plugins/chruby/chruby.plugin.zsh
41index 758b4a56c0aee1081e7acc18694bd8c9408ad082..998d92098fa5f9cac16da21c370238ea96373541 100644
42--- a/plugins/chruby/chruby.plugin.zsh
43+++ b/plugins/chruby/chruby.plugin.zsh
44@@ -16,12 +16,28 @@
45 # rvm and rbenv plugins also provide this alias
46 alias rubies='chruby'
47 
48+
49 _homebrew-installed() {
50     whence brew &> /dev/null
51+    _xit=$?
52+    if [ $_xit -eq 0 ];then
53+    	# ok , we have brew installed
54+	# speculatively we check default brew prefix
55+        if [ -h  /usr/local/opt/chruby ];then
56+		_brew_prefix="/usr/local/opt/chruby"
57+	else
58+		# ok , it is not default prefix 
59+		# this call to brew is expensive ( about 400 ms ), so at least let's make it only once
60+		_brew_prefix=$(brew --prefix chruby)
61+	fi
62+	return 0
63+   else
64+        return $_xit
65+   fi
66 }
67 
68 _chruby-from-homebrew-installed() {
69-  [ -r $(brew --prefix chruby) ] &> /dev/null
70+  [ -r _brew_prefix ] &> /dev/null
71 }
72 
73 _ruby-build_installed() {
74@@ -64,8 +80,8 @@ _chruby_dirs() {
75 }
76 
77 if _homebrew-installed && _chruby-from-homebrew-installed ; then
78-    source $(brew --prefix chruby)/share/chruby/chruby.sh
79-    source $(brew --prefix chruby)/share/chruby/auto.sh
80+    source $_brew_prefix/share/chruby/chruby.sh
81+    source $_brew_prefix/share/chruby/auto.sh
82     _chruby_dirs
83 elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then
84     source /usr/local/share/chruby/chruby.sh