And rename from make_bash_profile now that we're appending instead of
creating (since
c5d5414, Append exports to end of .bash_profile
instead of overwriting, 2013-09-19).
This more general form can be used to add even more paths, for example
our IPython and nosetest entry points.
-def make_bash_profile(home_dir, nano_dir):
- """Creates a .bash_profile file for nano setup
-
- Adds nano to the path and sets the default editor to nano
+def update_bash_profile(extra_paths=()):
+ """Create or append to a .bash_profile for Software Carpentry
+ Adds nano to the path, sets the default editor to nano, and adds
+ additional paths for other executables.
-
- nano_path = make_posix_path(nano_dir)
- contents = '\n'.join(['',
- '# Add nano to path and set as default editor',
- '# Added by the Software Carpentry nano installer',
- 'export PATH=$PATH:%s' % nano_path,
- 'export EDITOR=nano',
- ''])
- with open(os.path.join(home_dir, '.bash_profile'), 'a') as f:
- f.write(contents)
+ lines = [
+ '',
+ '# Add paths for Software-Carpentry-installed scripts and executables',
+ 'export PATH=$PATH:{}'.format(':'.join(
+ make_posix_path(path) for path in extra_paths),),
+ '',
+ '# Make nano the default editor',
+ 'export EDITOR=nano',
+ '',
+ ]
+ config_path = os.path.join(os.path.expanduser('~'), '.bash_profile')
+ with open(config_path, 'a') as f:
+ f.write('\n'.join(lines))
def make_posix_path(windows_path):
"""Convert a Windows path to a posix path"""
def make_posix_path(windows_path):
"""Convert a Windows path to a posix path"""