From 75f9d9cb17b40b99fe25affa7a5c01f2a66f1e30 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 7 Jan 2017 19:18:58 +0000 Subject: [PATCH] etc/profile --- etc/profile | 25 +++++++++++++----- etc/profile.d/envs | 2 +- etc/profile.d/functions | 52 +++++++++++++++++++++++++------------ etc/vim/source/vars.vim | 7 +++-- etc/vim/source/vars.vim.bak | 11 -------- 5 files changed, 60 insertions(+), 37 deletions(-) delete mode 100644 etc/vim/source/vars.vim.bak diff --git a/etc/profile b/etc/profile index ced7675e..7ef448bc 100755 --- a/etc/profile +++ b/etc/profile @@ -1,6 +1,8 @@ # # etc/profile # +# docker run --rm -it -v $NB_ROOT:$NB_ROOT alpine sh -c " . $NB_ROOT/etc/profile --debug && nb_repos && echo OK" +# [ "$1" = "--debug" ] && export NB_DEBUG="echo DEBUG: " && shift # @@ -60,6 +62,11 @@ else fi +nb_unset() { + 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 [ -n "$NB_DEBUG" ] && $NB_DEBUG "ERR: Unsupported shell. Please use bash, ksh93 or zsh." @@ -70,10 +77,12 @@ else #echo $NB_ETC_DIR; #return # Check to avoid system crash ! - [ ! -e "$NB_ETC_DIR/profile.d/functions" ] && echo "ERR: $NB_ETC_DIR: Wrong directory (no profile.d/functions)" 1>&2 && return 1 - #[ -e "$NB_ETC_DIR/profile.d/functions" ] && - . "$NB_ETC_DIR/profile.d/functions" || return [ -n "$NB_DEBUG" ] && $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) [ -n "$NB_DEBUG" ] && $NB_DEBUG "NB_ROOT=$NB_ROOT" @@ -84,21 +93,23 @@ else if [ -n "$NB_ROOT" ]; then #[ -e "$NB_ROOT/etc/profile.d/envs" ] && . "$NB_ROOT/etc/profile.d/envs" - #alias which=in_path + alias which=which_cache for i in \ ${NB_ROOT}/etc/profile.d/envs \ ${NB_ROOT}/etc/profile.d/aliases \ $(nb_repos_ls "etc/profile" "etc/profile.d/*.sh" | awk '$0 != "'${NB_ROOT}/etc/profile'"') \ ;do -# NB 13.12.16 $(nb_repos_ls "etc/profile" "etc/profile.d/*.sh" | grep -vFx "${NB_ROOT}/etc/profile") \ [ -n "$NB_DEBUG" ] && $NB_DEBUG ". $i" [ -r "$i" -a -f "$i" ] && . "$i" done - #unalias which + unalias which fi fi #export NB_LASTTIME=$(date +"%Y-%M-%d %T") -unset i tmp NB_ETC_DIR NB_DEBUG NB_LOOP +nb_unset +unset -f nb_unset 2> /dev/null + +return 0 diff --git a/etc/profile.d/envs b/etc/profile.d/envs index 6d6750da..b090c09f 100644 --- a/etc/profile.d/envs +++ b/etc/profile.d/envs @@ -52,7 +52,7 @@ MANPATH=$(env_add_path "$MANPATH" \ /usr/local/man\ /usr/local/memcached/share/man \ /opt/local/share/man \ - $(nb_repos_ls | xargs -n1 -IZ echo "Z/man" 2>/dev/null) \ + $(nb_repos_ls man) \ ) export MANPATH diff --git a/etc/profile.d/functions b/etc/profile.d/functions index 447fe288..6895df0e 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -735,10 +735,12 @@ while (@_) { } shell_replace() { - perl -ne 'if (/^.{1,3}>SHELL_REPLACE (.*)$/ .. /^.{1,3}SHELL_REPLACE (.*)$/ .. /^.{1,3}&2 -# NB 27.12.16 return -# NB 27.12.16 done -# NB 27.12.16 #/usr/bin/which -# NB 27.12.16 return 1 -# NB 27.12.16 } +#unset _which_cache +_which_cache="" +which_cache() { + #/usr/bin/which + local IFS=':' + local p + + # Cache + case "$_which_cache|" in + *"|$1=1|"*) + [ -n "$NB_DEBUG" ] && $NB_DEBUG "which_cache() $1=1" + return 0 + ;; + *"|$1=0|"*) + [ -n "$NB_DEBUG" ] && $NB_DEBUG "which_cache() $1=0" + return 1 + ;; + esac + + for p in $PATH; do + test -x "$p/$1" || continue + + _which_cache="$_which_cache|$1=1" + echo "$1" + return 0 + done + + _which_cache="$_which_cache|$1=0" + return 1 +} diff --git a/etc/vim/source/vars.vim b/etc/vim/source/vars.vim index 2358b046..a2fa83f4 100644 --- a/etc/vim/source/vars.vim +++ b/etc/vim/source/vars.vim @@ -1,9 +1,14 @@ " +" vim/source/vars.vim +" +" Command to check files per file types +" ">SHELL_REPLACE dbq t=mime orderby=id rows.fields=id,cmd_check out=cust cust="@id@ : @cmd_check@" sep=, preff=' \' quote_escape="'" quote="'" open='let mimeCheck = {\n' close='\}\n' let mimeCheck = { \'bash' : 'bash -c' \,'erb' : 'sh -c \"cat | erb -x - | ruby -c\" <' \,'html' : 'xmllint --noout --html' + \,'init' : 'init-checkconf' \,'json' : 'ruby -rjson -e ''puts JSON.parse(File.read(ARGV[0]))''' \,'perl' : 'perl -c -w' \,'php' : 'php --define error_reporting=22519 --define display_errors=1 --define log_errors=1 --define html_errors=0' @@ -14,5 +19,3 @@ let mimeCheck = { \,'yaml' : 'ruby -ryaml -e ''puts YAML.load_file(ARGV[0])''' \} "SHELL_REPLACE dbq t=mime rows.fields=id,cmd_check out=cust cust="@id@ : @cmd_check@" sep=, preff=' \' open='let mimeCheck = {\n' close='\}\n' -" -let mimeCheck = { -\} -" -"