From 57f782ee9f6b03af8b3c307d1754367c8952b133 Mon Sep 17 00:00:00 2001 From: Mark Caudill Date: Sat, 27 Jan 2024 20:39:36 -0500 Subject: [PATCH] Reorganize --- dot-bash_profile | 40 ++++++++++++++++++++++++++++++++++++++-- dot-bashrc | 39 ++++++++------------------------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/dot-bash_profile b/dot-bash_profile index 6e0f9b0..3e2536f 100644 --- a/dot-bash_profile +++ b/dot-bash_profile @@ -1,3 +1,39 @@ # shellcheck shell=bash -# shellcheck disable=SC1090 -test -f ~/.bashrc && source ~/.bashrc + +# From man 1 bash: +# When bash is invoked as an interactive login shell, or as a non-interactive +# shell with the --login option, it first reads and executes commands from the +# file /etc/profile, if that file exists. After reading that file, it looks +# for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads +# and executes commands from the first one that exists and is readable. + +# PATH +POTENTIAL_PATHS=( + ~/.krew/bin + ~/.local/bin + ~/bin + ~/.cargo/bin + ~/.pulumi/bin/ + ~linuxbrew/.linuxbrew/bin/ + /snap/bin + /usr/local/go/bin + /cygdrive/c/Go/bin + /usr/local/bin + /usr/local/sbin + /usr/bin + /usr/sbin + /bin + /sbin + /usr/games + /cygdrive/c/Program Files/Git/cmd +) +VALID_PATHS= +# Only add a path to PATH if it it exists and isn't already in PATH. VALID_PATHS is used as intermediary variable +for p in "${POTENTIAL_PATHS[@]}"; do + if [[ -d "${p}" ]]; then + if [[ ":${VALID_PATHS}:" != *":${p}:"* ]]; then + VALID_PATHS="${VALID_PATHS:+"${VALID_PATHS}:"}${p}" + fi + fi +done +export PATH="${VALID_PATHS}" diff --git a/dot-bashrc b/dot-bashrc index 984dcd0..373b2a9 100644 --- a/dot-bashrc +++ b/dot-bashrc @@ -1,5 +1,13 @@ # shellcheck shell=bash +# From man 1 bash: +# When an interactive shell that is not a login shell is started, bash reads +# and executes commands from /etc/bash.bashrc and ~/.bashrc, if these +# files exist. + +# shellcheck disable=SC1090 +[[ -f ~/.bash_profile ]] && source ~/.bash_profile + ####################################### ## ## Utility Functions @@ -51,37 +59,6 @@ export CDPATH=".:~:~/src" # General export VISUAL=vim -# PATH -POTENTIAL_PATHS=( - ~/.krew/bin - ~/.local/bin - ~/bin - ~/.cargo/bin - ~/.pulumi/bin/ - ~linuxbrew/.linuxbrew/bin/ - /snap/bin - /usr/local/go/bin - /cygdrive/c/Go/bin - /usr/local/bin - /usr/local/sbin - /usr/bin - /usr/sbin - /bin - /sbin - /usr/games - /cygdrive/c/Program Files/Git/cmd -) -VALID_PATHS= -# Only add a path to PATH if it it exists and isn't already in PATH. VALID_PATHS is used as intermediary variable -for p in "${POTENTIAL_PATHS[@]}"; do - if [[ -d "${p}" ]]; then - if [[ ":${VALID_PATHS}:" != *":${p}:"* ]]; then - debug "Adding ${p} to VALID_PATHS" - VALID_PATHS="${VALID_PATHS:+"${VALID_PATHS}:"}${p}" - fi - fi -done -export PATH="${VALID_PATHS}" # Environment Activations