Skip to content

Commit

Permalink
Only add modified PATH to login files in login shells (#48)
Browse files Browse the repository at this point in the history
* Only add modified `PATH` to login files in login shells

* Fix tests

* Apply suggestions from code review

---------

Co-authored-by: Ofek Lev <[email protected]>
  • Loading branch information
chrysle and ofek authored Jul 18, 2023
1 parent bed509e commit abfb4bc
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions userpath/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def config(self, location, front=True):
new_path = '{}{}{}'.format(head, pathsep, tail)
contents = 'export PATH="{}"'.format(new_path)

configs = {path.join(self.home, '.bashrc'): contents}

# https://github.com/ofek/userpath/issues/3#issuecomment-492491977
profile_path = path.join(self.home, '.profile')
bash_profile_path = path.join(self.home, '.bash_profile')
Expand All @@ -44,13 +42,11 @@ def config(self, location, front=True):
# Terminal.app runs a login shell by default for each new terminal window.
login_config = bash_profile_path

configs[login_config] = contents

return configs
return {login_config: contents}

@classmethod
def show_path_commands(cls):
return [['bash', '-i', '-c', 'echo $PATH'], ['bash', '-i', '-l', '-c', 'echo $PATH']]
return [['bash', '-i', '-l', '-c', 'echo $PATH']]


class Fish(Shell):
Expand Down Expand Up @@ -95,11 +91,12 @@ def config(self, location, front=True):
contents = 'export PATH="{}"'.format(new_path)

zdotdir = environ.get('ZDOTDIR', self.home)
return {path.join(zdotdir, '.zshrc'): contents, path.join(zdotdir, '.zprofile'): contents}

return {path.join(zdotdir, '.zprofile'): contents}

@classmethod
def show_path_commands(cls):
return [['zsh', '-i', '-c', 'echo $PATH'], ['zsh', '-i', '-l', '-c', 'echo $PATH']]
return [['zsh', '-i', '-l', '-c', 'echo $PATH']]


SHELLS = {
Expand Down

0 comments on commit abfb4bc

Please sign in to comment.