Add dynamic PATH helpers to bash profile#4
Draft
deyloop wants to merge 2 commits into
Draft
Conversation
Introduce path_prefix and path_postfix in .profile to prepend and append PATH entries while skipping duplicates. Refactor static PATH assignments to use these helpers, source .profile from .bash_profile for login shells, and replace the hardcoded opencode PATH in .bashrc with path_prefix. Co-authored-by: Anurup Dey <me.deyloop@gmail.com>
path_prefix and path_postfix now require each directory to exist before adding it to PATH. The opencode fallback in .bashrc uses the same check. Co-authored-by: Anurup Dey <me.deyloop@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes PATH construction dynamic by adding two POSIX
sh-compatible helpers and wiring the existing profile/bash config through them.path_prefix— prepends one or more directories toPATH, skipping duplicates and missing directoriespath_postfix— appends one or more directories toPATH, skipping duplicates and missing directoriesChanges
bash/.profile: definespath_prefixandpath_postfix, and replaces manualPATH="$dir:$PATH"/PATH="$PATH:$dir"assignments with calls to these helpersbash/.bash_profile: sources~/.profilebefore~/.bashrcso login shells pick up the shared PATH setup and helpersbash/.bashrc: usespath_prefixfor the opencode bin directory (with a POSIX fallback for non-login interactive shells that have not sourced.profile)Install check
Each directory is only added when it exists (
[ -d "$dir" ]), so PATH is not polluted with locations for tools that have not been installed yet.Why
.profilefor the functions?PATH and global environment variables already live in
.profileby design (for non-bash shells and login-only sourcing). Keeping the helpers there preservesshcompatibility and avoids re-sourcing the full profile on every interactive subshell.Example
Each directory is added only once and only if it exists, regardless of how many times the helpers are called.