feat: Improve way to determine and set the path containing the bash config
Before this: The bash config repo needed to be cloned in ~/.bash/ to work properly After this: The bash config repo can be move anywhere (for exemple in ~/.config/bash). The create-links.bash helper is adapted to this new behaviour. So you can clone anywhere and call create-links.bash from anywhere. Then the symbolic links in your home should be good and the config would load correctly.
This commit is contained in:
+40
-5
@@ -1,12 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -f "$HOME"/.nix-profile/etc/profile.d/hm-session-vars.sh ]; then
|
||||
source "$HOME"/.nix-profile/etc/profile.d/hm-session-vars.sh
|
||||
if [ -f "${HOME}"/.nix-profile/etc/profile.d/hm-session-vars.sh ]; then
|
||||
source "${HOME}"/.nix-profile/etc/profile.d/hm-session-vars.sh
|
||||
fi
|
||||
|
||||
if [ -f "$HOME"/.bash/profile ]; then source "$HOME"/.bash/profile; fi
|
||||
if [ -d "$HOME"/.bash/profile ]; then for file in "$HOME"/.bash/profile/*; do source "$file"; done; fi
|
||||
if [ -d "$HOME"/.bash/profile.d ]; then for file in "$HOME"/.bash/profile.d/*; do source "$file"; done; fi
|
||||
# Define the path to the directory of this file if not already set
|
||||
if [ -z "${BASH_CONFIG_DIR}" ]; then
|
||||
# Define a function to get the real path of a script
|
||||
# (works for most cases : either sourced script or executed script, posix shells)
|
||||
get_script_dir() {
|
||||
local target
|
||||
# Si appelé depuis un script (Bash), on regarde qui a appelé la fonction (${BASH_SOURCE[1]})
|
||||
# Si la fonction est exécutée directement dans le terminal, on se rabat sur ${BASH_SOURCE[0]} ou ${0}
|
||||
if [ -n "${BASH_SOURCE}" ]; then
|
||||
if [ "${#BASH_SOURCE[@]}" -gt 1 ]; then
|
||||
target="${BASH_SOURCE[1]}"
|
||||
else
|
||||
target="${BASH_SOURCE[0]}"
|
||||
fi
|
||||
elif [ -n "${ZSH_VERSION}" ]; then
|
||||
target="${(%):-%x}"
|
||||
else
|
||||
target="${0}"
|
||||
fi
|
||||
|
||||
# Résolution des liens symboliques POSIX
|
||||
while [ -L "${target}" ]; do
|
||||
local link
|
||||
link=$(readlink "${target}")
|
||||
case "${link}" in
|
||||
/*) target="${link}" ;;
|
||||
*) target="$(dirname "${target}")/${link}" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
(cd "$(dirname "${target}")" && pwd -P)
|
||||
}
|
||||
BASH_CONFIG_DIR=$(get_script_dir)
|
||||
fi
|
||||
|
||||
if [ -f "${BASH_CONFIG_DIR}"/profile ]; then source "${BASH_CONFIG_DIR}"/profile; fi
|
||||
if [ -d "${BASH_CONFIG_DIR}"/profile ]; then for file in "${BASH_CONFIG_DIR}"/profile/*; do source "$file"; done; fi
|
||||
if [ -d "${BASH_CONFIG_DIR}"/profile.d ]; then for file in "${BASH_CONFIG_DIR}"/profile.d/*; do source "$file"; done; fi
|
||||
|
||||
# This file is sourced by bash for login shells. The following line
|
||||
# runs your .bashrc and is recommended by the bash info pages.
|
||||
|
||||
Reference in New Issue
Block a user