From 1c8f1d99f7270233d0eddbe48d1c70cff6b7a630 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 17 May 2016 19:03:41 +0700 Subject: [PATCH] profile: Do not add to PATH if folder does not exist Pros: It does not add non-existing folder to PATH. Cons: Once the folder is created, the PATH has to be manually set or the session has to be restarted. --- .profile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.profile b/.profile index bb0e8e18..57bc3234 100644 --- a/.profile +++ b/.profile @@ -13,13 +13,13 @@ umask 027 ## to PATH, not prepend them. appendpath() { [ $# -eq 2 ] && PATHVAR=$2 || PATHVAR=PATH - if [ -z "$(eval echo \$$PATHVAR | grep "\(:\|^\)$1\(:\|$\)")" ]; then + if [ -d "$1" ] && [ -z "$(eval echo \$$PATHVAR | grep "\(:\|^\)$1\(:\|$\)")" ]; then eval export $PATHVAR="\$$PATHVAR:$1" fi } prependpath() { [ $# -eq 2 ] && PATHVAR=$2 || PATHVAR=PATH - if [ -z "$(eval echo \$$PATHVAR | grep "\(:\|^\)$1\(:\|$\)")" ]; then + if [ -d "$1" ] && [ -z "$(eval echo \$$PATHVAR | grep "\(:\|^\)$1\(:\|$\)")" ]; then eval export $PATHVAR="$1:\$$PATHVAR" fi } @@ -33,7 +33,7 @@ prependpath "${HOME}/.hackpool/" TEXDIR="${TEXDIR:-/usr/local/texlive}" if [ -d "${TEXDIR}" ]; then TEXYEAR=$(/bin/ls -1r "${TEXDIR}" | grep -m1 "[0-9]\{4\}") - TEXDISTRO=$(uname -m)-$(uname | tr "[[:upper:]]" "[[:lower:]]") + TEXDISTRO=$(uname -m)-$(uname | awk '{print tolower($0)}') TEXFOLDER="${TEXDIR}/${TEXYEAR}/bin/${TEXDISTRO}/" if [ -d "${TEXFOLDER}" ]; then appendpath $TEXFOLDER