From: Nicolas Boisselier Date: Wed, 2 Mar 2016 15:51:56 +0000 (+0000) Subject: zsh compatible X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=957a01bc2ac80076c563195a8c4bf3fcf3feb42b;p=nb.git zsh compatible --- diff --git a/etc/profile b/etc/profile index 8a534afc..5ab1e06e 100644 --- a/etc/profile +++ b/etc/profile @@ -1,17 +1,29 @@ # # ROOT PATH # -case "$BASH_SOURCE" in */*) path="${BASH_SOURCE%/*}";; *) path='.' ;; esac -[ -e "$path/profile.d/functions" ] && . "$path/profile.d/functions" -NB_ROOT=$(realpath ${path}/.. 2>/dev/null) -unset path +case "$BASH_SOURCE" in + */*) dir="${BASH_SOURCE%/*}";; + *) + case "$ZSH_NAME" in + *zsh) + dir=${(%):-%N} + dir=${dir%/*} + ;; + *) dir='.' ;; + esac + ;; +esac + +[ -e "$dir/profile.d/functions" ] && source "$dir/profile.d/functions" +NB_ROOT=$(realpath ${dir}/.. 2>/dev/null) +unset dir i if [ -z "$NB_ROOT" ]; then unset NB_ROOT else for i in ${NB_ROOT}/etc/profile.d/envs ${NB_ROOT}/etc/profile.d/aliases $NB_ROOT/etc/profile.d/*.sh; do - [ -r "$i" ] && . "$i" + [ -r "$i" ] && source "$i" done unset i tmp diff --git a/etc/profile.d/envs b/etc/profile.d/envs index 055f0e10..5dd0926c 100644 --- a/etc/profile.d/envs +++ b/etc/profile.d/envs @@ -56,27 +56,35 @@ esac # # PS1 # -h='\h' -color='' -#case $(tr '[:upper:]' '[:lower:]' <<<"$HOSTNAME") in -case "`hostname -f`" in - pi*) color=31 ;; - # ovh - yellow - *.ovh.net|*.kimsufi.com|*.ip-*.eu) color=33 ;; - # mac - magenta - Nicolas-Boisselier-MacBook*) h="macbook"; color=35 ;; - MacMini*) color=35 ;; - *.semantico.net|dev*|cst*|csp*|isp*) color=32 ;; - *) color=36 ;; -esac -char='$'; [ $UID = "0" ] && char='#' -if [ "$color_prompt" = yes -a -n "$color" ]; then - PS1="\[\033[01;${color}m\]\u@$h:\[\033[00m\]\W${char} " -else - PS1="\u@\h:\W${char} " -fi -unset h color char +case "$SHELL" in + */zsh) ;; + *) + + h='\h' + color='' + #case $(tr '[:upper:]' '[:lower:]' <<<"$HOSTNAME") in + case "`hostname -f`" in + pi*) color=31 ;; + # ovh - yellow + *.ovh.net|*.kimsufi.com|*.ip-*.eu) color=33 ;; + # mac - magenta + Nicolas-Boisselier-MacBook*) h="macbook"; color=35 ;; + MacMini*) color=35 ;; + *.semantico.net|dev*|cst*|csp*|isp*) color=32 ;; + *) color=36 ;; + esac + + char='$'; [ $UID = "0" ] && char='#' + if [ "$color_prompt" = yes -a -n "$color" ]; then + PS1="\[\033[01;${color}m\]\u@$h:\[\033[00m\]\W${char} " + else + PS1="\u@\h:\W${char} " + fi + + unset h color char + ;; +esac # # ls diff --git a/etc/profile.d/functions b/etc/profile.d/functions index 7943a152..0cd13f1e 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -47,7 +47,7 @@ shell_help_noarg() { shell_functions() { # NB 15.02.16 set | perl -ne '/^([a-z][\w_-]+) \(\)\s*$/ and print "$1\n"' - typeset -f | perl -ne '/^([a-z][\w_-]+) \(\)\s*$/ and print "$1\n"' + typeset -f | perl -ne '/^([a-z][\w_-]+) \(\)\s*\{*$/ and print "$1\n"' #set | perl -ne '/^([a-z][\w_-]+) \(\)\s*$/ and print "$1 "' | perl -pe 's/\s+$//' } @@ -56,17 +56,23 @@ shell_ssh() { declare server; server="$1"; shift declare tmp; tmp="/tmp/$FUNCNAME.$USER" ( - alias - eval type $(shell_functions|perl -pe 's/\s+/ /') | grep -v 'is a function$' - echo "[ -r /etc/profile ] && . /etc/profile" + alias | sed -e 's/^alias //' -e 's/^/alias /' + eval type $(shell_functions|perl -pe 's/\s+/ /') | grep -v ' function$' + echo "[ -r /etc/profile ] && source /etc/profile" ) | ssh "$server" "cat > $tmp || rm -vf $tmp" || return declare args if [ -z "$@" ]; then [ -z "$ssh_opt" ] && ssh_opt='-t' - ssh $ssh_opt "$server" "bash --rcfile $tmp && rm -f $tmp" + + case "$ZSH_NAME" in + *zsh) ssh $ssh_opt "$server" "source $tmp && zsh -f -d; rm -f $tmp" ;; + *) ssh $ssh_opt "$server" "bash --rcfile $tmp; rm -f $tmp" ;; + esac + else ssh $ssh_opt "$server" "bash && rm -f $tmp" <<< ". $tmp; $@" + fi }