]> git.nbdom.net Git - nb.git/commitdiff
etc/profile
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 9 Jan 2018 20:34:23 +0000 (20:34 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 9 Jan 2018 20:34:23 +0000 (20:34 +0000)
etc/profile

index 435c5177b2a1259cacbec6f13cebb0cd2b07f230..f2beb1df3643c049b9a6db1c7f7b62d84acb5f33 100755 (executable)
@@ -26,12 +26,12 @@ nb_file_as_tag() { [ "$(head -1 "$1")" = "# <NB_TAG>" ]; }
 # Avoid infinit loop. Eg: profile -> .bashrc -> profile
 #
 if [ -n "$NB_LOOP" ]; then
-  nb_debug "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0"
-  echo "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0 | Won't load !"
-  NB_LOOP=$(($NB_LOOP+1))
-  unset NB_LOOP
-  exit
-  return 2>/dev/null || exit # if executable
+       nb_debug "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0"
+       echo "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0 | Won't load !"
+       NB_LOOP=$(($NB_LOOP+1))
+       unset NB_LOOP
+       exit
+       return 2>/dev/null || exit # if executable
 fi
 nb_debug "ENVS: BASH_SOURCE=$BASH_SOURCE \$0=$0"
 
@@ -45,84 +45,84 @@ unset NB_ETC_DIR
 #[ "${BASH-no}" != "no" ] && echo Is BASH
 #echo BASH_SOURCE=$BASH_SOURCE ZSH_VERSION=$ZSH_VERSION KSH_VERSION=$KSH_VERSION
 if [ -n "$BASH_SOURCE" ]; then
-  NB_ETC_DIR="${BASH_SOURCE%/*}"
+       NB_ETC_DIR="${BASH_SOURCE%/*}"
 
 elif [ -n "$ZSH_VERSION" ]; then
-  eval 'NB_ETC_DIR=${(%):-%N}'
-  NB_ETC_DIR=${dir%/*}
+       eval 'NB_ETC_DIR=${(%):-%N}'
+       NB_ETC_DIR=${dir%/*}
 
 elif [ "$KSH_VERSION" != "" ]; then
 #elif eval '[[ -n ${.sh.file} ]]' 2>/dev/null; then
-  eval 'NB_ETC_DIR="$(dirname "${.sh.file}")"'
+       eval 'NB_ETC_DIR="$(dirname "${.sh.file}")"'
 
 elif [ -r /etc/profile.d/nb.sh ]; then
-  NB_ETC_DIR=$(dirname $(grep '\. ' -m1 /etc/profile.d/nb.sh | cut -d'.' -f2 /etc/profile.d/nb.sh))
+       NB_ETC_DIR=$(dirname $(grep '\. ' -m1 /etc/profile.d/nb.sh | cut -d'.' -f2 /etc/profile.d/nb.sh))
 
 else
-  # Alpine, busybox, ...
-  # We guess by looking for file !!
-  tmp=$PWD
-  for i in /*/*/etc/profile.d/nb.sh /*/*/*/etc/profile.d/nb.sh; do
+       # Alpine, busybox, ...
+       # We guess by looking for file !!
+       tmp=$PWD
+       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
+               cd "$(dirname "$i")"/.. 1>/dev/null 2>&1 || continue
+               nb_file_as_tag ../profile || continue
 
-    NB_ETC_DIR=$PWD #|| unset NB_ETC_DIR
-    break
+               NB_ETC_DIR=$PWD #|| unset NB_ETC_DIR
+               break
 
-  done
-  cd "$tmp"
+       done
+       cd "$tmp"
 
 fi
 
 _nb_unset() {
-  unset i tmp NB_ETC_DIR NB_DEBUG NB_LOOP
-  return 0
+       unset i tmp NB_ETC_DIR NB_DEBUG NB_LOOP
+       return 0
 }
 
 if [ -z "$NB_ETC_DIR" -o "$NB_ETC_DIR" = "/" ]; then
-  export NB_UNSUPORTED=1
-  nb_debug "ERR: Unsupported shell. Please use bash, ksh93 or zsh."
+       export NB_UNSUPORTED=1
+       nb_debug "ERR: Unsupported shell. Please use bash, ksh93 or zsh."
 
 else
-  unset NB_UNSUPORTED
-  #echo "+$NB_ETC_DIR"
-  #echo $NB_ETC_DIR; #return
-
-  # Check to 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
-    _nb_unset
-    return 1
-  fi
-
-  export NB_ROOT=$(realpath $NB_ETC_DIR/.. 2>/dev/null)
-  nb_debug "NB_ROOT=$NB_ROOT"
-
-  #
-  # Profiles
-  #
+       unset NB_UNSUPORTED
+       #echo "+$NB_ETC_DIR"
+       #echo $NB_ETC_DIR; #return
+
+       # Check to 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
+               _nb_unset
+               return 1
+       fi
+
+       export NB_ROOT=$(realpath $NB_ETC_DIR/.. 2>/dev/null)
+       nb_debug "NB_ROOT=$NB_ROOT"
+
+       #
+       # Profiles
+       #
 # NB 09.01.18       $(true || nb_repos_ls "etc/profile" "etc/profile.d/*.sh" | awk '!/^\/etc\// && $0 != "'${NB_ROOT}/etc/profile'"') \
-  if [ -n "$NB_ROOT" ]; then
-
-    alias which=which_cache
-    for i in \
-      ${NB_ROOT}/etc/profile.d/envs \
-      ${NB_ROOT}/etc/profile.d/aliases \
-      ${NB_ROOT}/etc/profile.d/*.sh \
-      $([ "$NB_NO_REPOS" = "yes" ] || nb_repos_ls "etc/profile" "etc/profile.d/*.sh" | grep -v "^$NB_ROOT/") \
-    ; do
-       case "$i" in
-               */etc/profile) nb_file_as_tag "$i" && nb_debug "IGNORE $i" && continue ;;
-               /etc/profile*) continue ;;
-       esac
-      nb_debug ". $i"
-      #[ -r "$i" -a -f "$i" ] && . "$i"
-    done
-    unalias which
-
-  fi
+       if [ -n "$NB_ROOT" ]; then
+
+               alias which=which_cache
+               for i in \
+                       ${NB_ROOT}/etc/profile.d/envs \
+                       ${NB_ROOT}/etc/profile.d/aliases \
+                       ${NB_ROOT}/etc/profile.d/*.sh \
+                       $([ "$NB_NO_REPOS" = "yes" ] || nb_repos_ls "etc/profile" "etc/profile.d/*.sh" | grep -Ev "^($NB_ROOT/|/etc/profile)") \
+               ; do
+                       case "$i" in
+                               # no multiple include from other branch
+                               */etc/profile) nb_file_as_tag "$i" && nb_debug "IGNORE $i" && continue ;;
+                       esac
+                       nb_debug ". $i"
+                       [ -r "$i" -a -f "$i" ] && . "$i"
+               done
+               unalias which
+
+       fi
 
 fi