How to update $ PATH

I am writing a python / pygtk application adding some user scripts (bash) to a specific folder in $ HOME (e.g. ~/.custom_scripts).

I want to make this folder available in $PATH. Therefore, every time a python application adds a script, the script can be instantly available when the user opens a terminal (e.g. gnome-terminal).

Where do you suggest "injecting" that $ PATH dependecy? .bashrc, /etc/profile.detc.? What advantages / disadvantages can I meet?

For example, if I add a script to export a new path to /etc/profile.d, the path is not updated until I re-write.

thank

+3
source share
7 answers

~ / .bashrc is read every time the gnome terminal is open (it is assumed that the user has a SHELL installed in / bin / bash).

Be sure to check os.environ ['PATH'] to see if the directory is added so that the script does not add it more than once.

+1
source

.profilewill be a reasonable place if it is installed by the user; /etc/profile.dfor system-wide installations. (Of course, you will need root to do this.)

Your installer will not be able to change the path to the current shell (unless it runs through source, which will be ... odd.)

+2
source

, $HOME, $HOME/bin, .

+2

/etc/profile.d

~/.bashrc

"$ source ~/.bashrc" .

+1

: , PATH, ...

os:

import os
USER_HOME = os.path.expanduser('~')
os.environ['PATH'] += ":" + os.path.join(USER_HOME, '.custom_scripts')

:~/.custom_scripts $PATH, PATH .

+1

. , PATH, . , , , PATH.

, , ?

+1

Why do not you install the appropriate the PATHfirst time you call your module (i.e. in your module __init__.py):

# this is your module __init__.py
import sys
eggs = ['/path/to/egg/1.egg', '/path/to/egg/2.egg']
for egg in eggs:
    sys.path.append(egg)
+1
source

Source: https://habr.com/ru/post/1765175/


All Articles