@@ -121,16 +121,33 @@ def append_to_config_file(path, shellcode):
121
121
fh .write (shellcode )
122
122
print ("Added." , file = sys .stderr )
123
123
124
-
125
- def link_user_rcfiles ():
126
- # TODO: warn if running as superuser
124
+ def link_zsh_user_rcfile (zsh_fpath = None ):
127
125
zsh_rcfile = os .path .join (os .path .expanduser (os .environ .get ("ZDOTDIR" , "~" )), ".zshenv" )
128
- append_to_config_file (zsh_rcfile , zsh_shellcode .format (zsh_fpath = get_activator_dir ()))
126
+ append_to_config_file (zsh_rcfile , zsh_shellcode .format (zsh_fpath = zsh_fpath or get_activator_dir ()))
129
127
128
+ def link_bash_user_rcfile ():
130
129
bash_completion_user_file = os .path .expanduser ("~/.bash_completion" )
131
130
append_to_config_file (bash_completion_user_file , bash_shellcode .format (activator = get_activator_path ()))
132
131
133
132
133
+ def link_user_rcfiles ():
134
+ # TODO: warn if running as superuser
135
+ link_zsh_user_rcfile ()
136
+ link_bash_user_rcfile ()
137
+
138
+ def add_zsh_system_dir_to_fpath_for_user ():
139
+ if "zsh" not in os .environ .get ("SHELL" ):
140
+ return
141
+ try :
142
+ zsh_system_dir = get_zsh_system_dir ()
143
+ fpath_output = subprocess .check_output ([os .environ ["SHELL" ], "-c" , 'printf "%s\n " "${fpath[@]}"' ])
144
+ for fpath in fpath_output .decode ().splitlines ():
145
+ if fpath == zsh_system_dir :
146
+ return
147
+ link_zsh_user_rcfile (zsh_fpath = zsh_system_dir )
148
+ except (FileNotFoundError , subprocess .CalledProcessError ):
149
+ pass
150
+
134
151
def main ():
135
152
global args
136
153
args = parser .parse_args ()
@@ -160,6 +177,8 @@ def main():
160
177
for destination in destinations :
161
178
install_to_destination (destination )
162
179
180
+ add_zsh_system_dir_to_fpath_for_user ()
181
+
163
182
if args .dest is None :
164
183
print ("Please restart your shell or source the installed file to activate it." , file = sys .stderr )
165
184
0 commit comments