]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/functions
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 5 Apr 2018 02:20:49 +0000 (03:20 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 5 Apr 2018 02:20:49 +0000 (03:20 +0100)
etc/profile
etc/profile.d/functions

index 3c083c252bddebac8bb7f750200d18bb84c12670..07a13e4495cfb4b13e85728574dfcfd0993ae1ac 100755 (executable)
@@ -21,7 +21,7 @@ nb_debug() {
        return 0
 }
 
-nb_file_as_tag() { [ "$(head -1 "$1")" = "# <NB_TAG>" ]; }
+_nb_file_has_tag() { [ "$(head -1 "$1")" = "# <NB_TAG>" ]; }
 
 #
 # Avoid infinit loop. Eg: profile -> .bashrc -> profile
@@ -66,7 +66,7 @@ else
        for i in /*/*/etc/profile.d/nb.sh /*/*/*/etc/profile.d/nb.sh; do
 
                cd "$(dirname "$i")"/.. 1>/dev/null 2>&1 || continue
-               nb_file_as_tag ../profile || continue
+               _nb_file_has_tag ../profile || continue
 
                NB_ETC_DIR=$PWD #|| unset NB_ETC_DIR
                break
@@ -78,6 +78,7 @@ fi
 
 _nb_unset() {
        unset i tmp NB_ETC_DIR NB_DEBUG NB_LOOP
+       unset -f _nb_file_has_tag 2> /dev/null
        return 0
 }
 
@@ -90,7 +91,7 @@ else
        #echo "+$NB_ETC_DIR"
        #echo $NB_ETC_DIR; #return
 
-       # Check to avoid system crash !
+       # Load source file "functions" and avoid system crash !
        nb_debug ". $NB_ETC_DIR/profile.d/functions"
        if [ ! -e "$NB_ETC_DIR/profile.d/functions" ] || ! . "$NB_ETC_DIR/profile.d/functions"; then
                echo "ERR: $NB_ETC_DIR: Wrong directory (no profile.d/functions)" 1>&2
@@ -116,7 +117,7 @@ else
                ; do
                        case "$i" in
                                # no multiple include from other branch
-                               */etc/profile) nb_file_as_tag "$i" && nb_debug "IGNORE $i" && continue ;;
+                               */etc/profile) _nb_file_has_tag "$i" && nb_debug "IGNORE $i" && continue ;;
                        esac
                        nb_debug ". $i"
                        [ -r "$i" -a -f "$i" ] && . "$i"
index 792e8f2e4ce22e8af53a0198ac10ac867d83e736..1e56044479d8315c4b5c96767a9f44d377bc7a93 100644 (file)
@@ -825,7 +825,6 @@ _which_cache=""
 which_cache() {
        #/usr/bin/which
        local IFS=':'
-       local p
 
        # Cache
        case "$_which_cache|" in
@@ -840,6 +839,7 @@ which_cache() {
        esac
        #nb_debug "which_cache() $1=?"
 
+       local p
        for p in $PATH; do
                test -x "$p/$1" || continue