From 1a7a850efaff3d95e6ec6c7fcf92280494bcca09 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sat, 22 Aug 2026 02:16:49 +0200 Subject: [PATCH] fix: Simplify create-links.bash path resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the ~30-line get_script_dir() copy (duplicated a third time from bashrc/bash_profile) with a one-liner. This script is always executed directly, never sourced from another file, so BASH_SOURCE[0] reliably points to itself — the extra logic in get_script_dir() for the sourced-from-elsewhere case doesn't apply here. --- create-links.bash | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/create-links.bash b/create-links.bash index 092be28..04a2653 100755 --- a/create-links.bash +++ b/create-links.bash @@ -2,37 +2,7 @@ # 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) + BASH_CONFIG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" fi cd "${HOME}" || exit 1