Skip to content

Add dynamic PATH helpers to bash profile#4

Draft
deyloop wants to merge 2 commits into
mainfrom
cursor/bash-profile-path-functions-82e7
Draft

Add dynamic PATH helpers to bash profile#4
deyloop wants to merge 2 commits into
mainfrom
cursor/bash-profile-path-functions-82e7

Conversation

@deyloop

@deyloop deyloop commented Jul 9, 2026

Copy link
Copy Markdown
Owner

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 to PATH, skipping duplicates and missing directories
  • path_postfix — appends one or more directories to PATH, skipping duplicates and missing directories

Changes

  • bash/.profile: defines path_prefix and path_postfix, and replaces manual PATH="$dir:$PATH" / PATH="$PATH:$dir" assignments with calls to these helpers
  • bash/.bash_profile: sources ~/.profile before ~/.bashrc so login shells pick up the shared PATH setup and helpers
  • bash/.bashrc: uses path_prefix for 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 .profile for the functions?

PATH and global environment variables already live in .profile by design (for non-bash shells and login-only sourcing). Keeping the helpers there preserves sh compatibility and avoids re-sourcing the full profile on every interactive subshell.

Example

path_prefix "$HOME/.local/bin" "$SCRIPTS_DIR"
path_postfix "$HOME/.local/go/bin" "$GOPATH/bin"

Each directory is added only once and only if it exists, regardless of how many times the helpers are called.

Open in Web Open in Cursor 

cursoragent and others added 2 commits July 9, 2026 06:42
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants