From 2583f20503587517209aceb05a9e6b4eaa0c4985 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 25 Nov 2016 15:07:50 +0100 Subject: [PATCH] nb_repo --- etc/profile | 16 ++++------- etc/profile.d/aliases | 1 - etc/profile.d/envs | 36 ++++++++++++++++------- etc/profile.d/functions | 63 +++++++++++++++++++++++++++++++++++++++-- etc/profile.d/nb.sh | 55 ++--------------------------------- 5 files changed, 94 insertions(+), 77 deletions(-) diff --git a/etc/profile b/etc/profile index 83d96c1c..0f66d78d 100755 --- a/etc/profile +++ b/etc/profile @@ -1,9 +1,11 @@ -#echo $BASH_SOURCE # -# Avoid infinit loop. Eg: profile -> .bashrc -> profile +# etc/profile # [ "$1" = "--debug" ] && export NB_DEBUG="echo DEBUG: " && shift +# +# Avoid infinit loop. Eg: profile -> .bashrc -> profile +# #NB_DEBUG='echo ' if [ -n "$NB_LOOP" ]; then [ -n "$NB_DEBUG" ] && $NB_DEBUG "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0" @@ -45,15 +47,9 @@ else for i in /*/*/etc/profile.d/functions /*/*/*/etc/profile.d/functions; do cd "$(dirname "$i")"/.. &> /dev/null || continue [ -e profile.d/envs ] || continue - NB_CURRENT_DIR=`pwd` || unset NB_CURRENT_DI + NB_CURRENT_DIR=`pwd` || unset NB_CURRENT_DIR break - #[ -r "$i" ] && NB_CURRENT_DIR=$(dirname "$i")/../../.. && break done -# NB 24.11.16 for i in /*/*/bin/nb-install /*/*/*/bin/nb-install; do -# NB 24.11.16 ls $(dirname "$i")/../..; break -# NB 24.11.16 break -# NB 24.11.16 [ -r "$i" ] && NB_CURRENT_DIR=$(dirname "$i")/../.. && break -# NB 24.11.16 done fi @@ -78,7 +74,7 @@ else #${NB_ROOT}/etc/profile.d/*.sh for i in \ ${NB_ROOT}/etc/profile.d/aliases \ - $(nb-repo-dirs "etc/profile" "etc/profile.d/*.sh" | grep -vFx "${NB_ROOT}/etc/profile") \ + $(nb_repo "etc/profile" "etc/profile.d/*.sh" | grep -vFx "${NB_ROOT}/etc/profile") \ ;do [ -n "$NB_DEBUG" ] && $NB_DEBUG "OK: . $i" [ -r "$i" -a -f "$i" ] && . "$i" diff --git a/etc/profile.d/aliases b/etc/profile.d/aliases index 77f4065e..15ab0c93 100644 --- a/etc/profile.d/aliases +++ b/etc/profile.d/aliases @@ -8,7 +8,6 @@ #-------------------------------------------------------------------------------- # Others # -alias grep='grep --color=auto' which blkid &>/dev/null alias uuid-hds='blkid -o full -s UUID' alias dpkg-sort-size="dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1nr" which apg &>/dev/null && alias password-gener='apg -m 12 -x 12 -a 0 -M L|head -1;' diff --git a/etc/profile.d/envs b/etc/profile.d/envs index eb5f1b4c..220c48e4 100644 --- a/etc/profile.d/envs +++ b/etc/profile.d/envs @@ -20,8 +20,8 @@ if true || env_add_path &>/dev/null; then # # PATH # -[ -n "$NB_ROOT" ] && PATH=$(env_add_path "$PATH" "$NB_ROOT/bin") # to find nb-repo-dirs - #$($NB_ROOT/bin/nb-repo-dirs bin sbin) +[ -n "$NB_ROOT" ] && PATH=$(env_add_path "$PATH" "$NB_ROOT/bin") # to exec tools + #$($NB_ROOT/bin/nb_repo bin sbin) PATH=$(env_add_path "$PATH" \ /bin \ /sbin \ @@ -33,7 +33,7 @@ PATH=$(env_add_path "$PATH" \ /usr/local/sbin \ /usr/X11/bin/ \ /usr/share/awstats/tools \ - $(nb-repo-dirs bin sbin) \ + $(nb_repo bin sbin) \ /home/bin \ $HOME/bin \ ) @@ -47,7 +47,7 @@ MANPATH=$(env_add_path "$MANPATH" \ /usr/local/man\ /usr/local/memcached/share/man \ /opt/local/share/man \ - $(nb-repo-dirs | xargs -n1 -IZ echo "Z/man" 2>/dev/null) \ + $(nb_repo | xargs -n1 -IZ echo "Z/man" 2>/dev/null) \ ) export MANPATH @@ -70,7 +70,12 @@ case "$BASH" in */sh) SHELL_NAME=sh ;; */bash) SHELL_NAME=bash ;; *) - [ -n "$ZSH_NAME" ] && SHELL_NAME=zsh + case "$(realpath /bin/grep)" in + *busybox*) SHELL_NAME="busybox" ;; + *) + [ -n "$ZSH_NAME" ] && SHELL_NAME=zsh + ;; + esac ;; esac export SHELL_NAME @@ -90,7 +95,6 @@ fi # # PS1 # - if is_prompt; then case "$SHELL_NAME" in bash) @@ -126,17 +130,27 @@ fi # ls_opt=' -F' ll_opt=' -alh' -if [ -n "$DARWIN" ]; then - [ "$color_prompt" = yes ] && ls_opt="$ls_opt -G" -else - [ "$color_prompt" = yes ] && ls_opt="$ls_opt --color=auto" - ll_opt="$ll_opt --time-style=long-iso" + +if [ "$SHELL_NAME" != "busybox" ]; then + + if [ -n "$DARWIN" ]; then + [ "$color_prompt" = yes ] && ls_opt="$ls_opt -G" + else + [ "$color_prompt" = yes ] && ls_opt="$ls_opt --color=auto" + ll_opt="$ll_opt --time-style=long-iso" + fi + fi [ -n "$ls_opt" ] && alias ls="ls${ls_opt}" [ -n "$ll_opt" ] && alias ll="ls${ll_opt}" unset ls_opt ll_opt +# +# Alias grep +# +[ "$SHELL_NAME" = "busybox" ] || alias grep='grep --color=auto' + # # bye # diff --git a/etc/profile.d/functions b/etc/profile.d/functions index ea29f14f..ec1da1e4 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -3,6 +3,63 @@ # FUNCTIONS - SH # ################################################################################# +nb_repo() { +# NB 24.11.16: TODO +if true && which perl &> /dev/null; then + nb-repo-dirs $@ +else + + [ -z "$FUNCNAME" ] && local FUNCNAME='nb_repo' + if [ -z "$*" ]; then + # Find repos + ( + echo "$NB_ROOT" + ( + ls -d1 \ + /*/*/.nb-install \ + /usr/local/src/*/.nb-install \ + \ + /home/*/*/.nb-install \ + /Users/*/*/.nb-install \ + \ + /home/*/git/*/.nb-install \ + /Users/*/git/*/.nb-install \ + \ + /home/*/app/*/.nb-install \ + /Users/*/app/*/.nb-install \ + \ + /home/*/code/*/.nb-install \ + /Users/*/code/*/.nb-install \ + | xargs -n1 dirname \ + | xargs -n1 realpath \ + ) 2>/dev/null + ) | uniq + + else + + # Look for paths + local d f i repo ifs_bak="$IFS"; IFS=$'\n' + for d in `$FUNCNAME`; do + + for f in "$@"; do + + false && echo "====$d/$f" + #for repo in $(ls -d1 $d/$f 2>/dev/null); do + for repo in $d/$f; do + [ -e "$repo" ] && echo "$repo" + done + + done + + done + + IFS="$ifs_bak" + + fi + +fi +} + timeout() { if which timeout 1>/dev/null; then timeout -- $@ @@ -567,8 +624,10 @@ is_empty() { [[ -z $(ls -A "/$1" | head -1) ]]; } is_prompt() { #[[ $- == *i* ]] && echo "Interactive" || echo "Not interactive" - [[ $- == *i* ]] && return 0 - return 1 + case "$-" in + *i*) return 0 ;; + *) return 1 ;; + esac } url2nc() { diff --git a/etc/profile.d/nb.sh b/etc/profile.d/nb.sh index 388071c6..efb44230 100644 --- a/etc/profile.d/nb.sh +++ b/etc/profile.d/nb.sh @@ -1,59 +1,8 @@ -nb_repo() { -# NB 24.11.16: TODO -if false && which perl &> /dev/null; then - nb-repo-dirs $@ -else - - if [ -z "$*" ]; then - # Find repos - ( - echo "$NB_ROOT" - ( - ls -d1 ` \ - /*/*/.nb-instal \ - /usr/local/src/*/.nb-install \ - - /home/*/*/.nb-instal \ - /Users/*/*/.nb-instal \ - - /home/*/git/*/.nb-instal \ - /Users/*/git/*/.nb-instal \ - - /home/*/app/*/.nb-instal \ - /Users/*/app/*/.nb-instal \ - - /home/*/code/*/.nb-instal \ - /Users/*/code/*/.nb-instal \ - ` \ - | xargs -n1 dirname \ - | xargs -n1 realpath \ - ) 2>/dev/null - ) | uniq - - else - # Look for files - local ifs_bak="$IFS"; IFS=$'\n' - local d f i repo -#eval 'ls /opt/nb/etc/profile.d/*.sh' - for d in `$FUNCNAME`; do - #for d in "$NB_ROOT"; do - for f in "$@"; do - for repo in $(ls -d $d/$f); do - echo "$repo" - done - done - done - IFS="$ifs_bak" - fi - -fi -} - nb_repos_commit_push() { shell_help "Commit each repos whith a comment" "$@" && return local status local pwd=`pwd` - for i in $(nb-repo-dirs); do + for i in $(nb_repo); do cd "$i" || continue printf ">%s\n" "$i" @@ -71,7 +20,7 @@ nb_repos_status() { shell_help "List repos git status" "$@" && return local status local pwd=`pwd` - for i in $(nb-repo-dirs); do + for i in $(nb_repo); do cd "$i" || continue status=$(git status --short "$i"|sed 's/^/ /') -- 2.47.3