From a532dde5808a0f89b334b2a8cc04f558dfad975b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Reu=C3=9Fe?= Date: Mon, 27 Jul 2015 13:23:05 +0200 Subject: [PATCH] =?UTF-8?q?Leaver=20user=E2=80=99s=20PATH=20untouched.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of adding the location of qfc to the user’s PATH, this leaves PATH untouched and calls qfc at an arbitrary install location instead. In addition to not adding noise to the user’s path for just one script, this also allows having qfc installed to a location other than ~/.qfc. --- bin/qfc.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/qfc.sh b/bin/qfc.sh index b7ce9b8..27caaf8 100755 --- a/bin/qfc.sh +++ b/bin/qfc.sh @@ -17,8 +17,14 @@ function get_cursor_position(){ echo "$row $col" } -if [[ -d ~/.qfc/ ]]; then - export PATH=~/.qfc/bin:"${PATH}" +# Determine the absolute path to the QFC script. +if [[ -n "$BASH_VERSION" ]]; then + # Bash doesn’t evaluate $0 the right way when the script is sourced; + # use $BASH_SOURCE instead. + QFC=$(realpath $(dirname ${BASH_SOURCE[0]}))/qfc +else + # In zsh, $0 is consistent between sourcing and script invocation. + QFC=$(realpath $(dirname $0))/qfc fi if [[ -n "$ZSH_VERSION" ]]; then @@ -38,7 +44,7 @@ if [[ -n "$ZSH_VERSION" ]]; then # instruct qfc to store the result (completion path) into a temporary file tmp_file=$(mktemp -t qfc.XXXXXXX) -