]> git.nbdom.net Git - nb.git/commitdiff
zsh compatible
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 2 Mar 2016 15:51:56 +0000 (15:51 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 2 Mar 2016 15:51:56 +0000 (15:51 +0000)
etc/profile
etc/profile.d/envs
etc/profile.d/functions

index 8a534afc0bdd783bd83b13b48aaa424c4b6cad3a..5ab1e06e028f72a85fb35a8e35a365c6a78d1732 100644 (file)
@@ -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
 
index 055f0e107f38d65c3ad00d7c048bd19493166054..5dd0926c6cf5dc8f8876d8533ec0b0a7a09def5e 100644 (file)
@@ -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
index 7943a152b0bc023b3f0709d723ef81b33f4723a7..0cd13f1e3877b375ad3ea70dadde7e622a2b0c4f 100644 (file)
@@ -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
 }