Skip to content

prepend values to PATH only when missing#664

Open
vinchatl wants to merge 1 commit intoingydotnet:masterfrom
vinchatl:rc-script
Open

prepend values to PATH only when missing#664
vinchatl wants to merge 1 commit intoingydotnet:masterfrom
vinchatl:rc-script

Conversation

@vinchatl
Copy link
Copy Markdown

This fixes cases where executing source ~/.bashrc (after a change unrelated to git-subrepo) would prepend the git-subrepo root to the PATH variable each time the .rc file is called, leading to an always increasing PATH size with only duplicates.

Implementation is inspired by default .bashrc with pattern-matching on PATH variable.

.rc

export PATH=$GIT_SUBREPO_ROOT/lib:$PATH
export MANPATH=$GIT_SUBREPO_ROOT/man:$MANPATH
if ! [[ "$PATH" =~ "$GIT_SUBREPO_ROOT/lib:" ]]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because .rc isn't a bash file. As can be see in lines previous to this one it is used by many shells and =~ is a bash only operator. This needs to use posix shell commands to accomplish. I agree that this unconditionally updates your path, but you must be doing a lot of sourcing your bashrc before you would notice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants