@@ -121,16 +121,33 @@ def append_to_config_file(path, shellcode):
121121 fh .write (shellcode )
122122 print ("Added." , file = sys .stderr )
123123
124-
125- def link_user_rcfiles ():
126- # TODO: warn if running as superuser
124+ def link_zsh_user_rcfile (zsh_fpath = None ):
127125 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 ()))
129127
128+ def link_bash_user_rcfile ():
130129 bash_completion_user_file = os .path .expanduser ("~/.bash_completion" )
131130 append_to_config_file (bash_completion_user_file , bash_shellcode .format (activator = get_activator_path ()))
132131
133132
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+
134151def main ():
135152 global args
136153 args = parser .parse_args ()
@@ -160,6 +177,8 @@ def main():
160177 for destination in destinations :
161178 install_to_destination (destination )
162179
180+ add_zsh_system_dir_to_fpath_for_user ()
181+
163182 if args .dest is None :
164183 print ("Please restart your shell or source the installed file to activate it." , file = sys .stderr )
165184
0 commit comments