From a4b31794d10bef9be211f661898bd012cf4e5566 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 23 Oct 2014 16:14:51 +0200 Subject: [.zshrc] recursive call of specific scripts Specific scripts loop rewritten in a much cleaner way. --- zshrc | 73 ++++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/zshrc b/zshrc index a2fff9b..c143d50 100644 --- a/zshrc +++ b/zshrc @@ -6,12 +6,12 @@ # # If you want to add a file, name it specifically in the form # -# $ZDOTDIR/??_*.zsh +# $ZDOTDIR/??_*.zsh # # Where "??" should be a two-digit number. # With that, file ``10_Toto.zsh'' would be parsed before # file ``20_Tutu.zsh'', allowing you ordering your scripts. -# +# # If you want to make user, host or network specific configurations, # add your specific scripts to the folders # - "sys:$(uname -s)" for OS-specific conf, @@ -55,6 +55,38 @@ export USER HOST DOMAIN UID if [ -d $ZDOTDIR ]; then + recurse_load() { + local script=$1 + local root=$2 + + for f in \ + net:$DOMAIN \ + host:$HOST \ + sys:$OSNAME \ + user:$USER \ + user:$SUDO_USER + do + if test -d $root/$f + then + subscript=$root/$f/$script + if test -f $subscript + then + __debug -n "${${subscript:h}##$ZDOTDIR\/}/$script... "; + source $subscript + __debug + fi + if test -f $subscript.gpg + then + __debug -n "${${subscript:h}##$ZDOTDIR\/}/$script [CRYPTED]... "; + eval $(gpg --quiet --decrypt $subscript.gpg) + __debug + fi + + recurse_load $script $root/$f + fi + done + } + for script in $ZDOTDIR/??_*.zsh do @@ -62,42 +94,7 @@ if [ -d $ZDOTDIR ]; then source $script __debug - for i in "net:$DOMAIN"\ - "host:$HOST"\ - "sys:$OSNAME"\ - "user:$USER"\ - "user:$USER/net:$DOMAIN"\ - "user:$SUDO_USER"\ - "net:$DOMAIN/host:$HOST"\ - "net:$DOMAIN/sys:$OSNAME"\ - "net:$DOMAIN/user:$USER"\ - "net:$DOMAIN/user:$SUDO_USER"\ - "net:$DOMAIN/host:$HOST/sys:$OSNAME"\ - "net:$DOMAIN/host:$HOST/user:$USER"\ - "net:$DOMAIN/host:$HOST/user:$SUDO_USER"\ - "net:$DOMAIN/host:$HOST/sys:$OSNAME"\ - "net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$USER"\ - "net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$SUDO_USER"\ - "host:$HOST/sys:$OSNAME"\ - "host:$HOST/user:$USER"\ - "host:$HOST/user:$SUDO_USER"\ - "host:$HOST/sys:$OSNAME/user:$USER"\ - "host:$HOST/sys:$OSNAME/user:$SUDO_USER" - do - specific_script=${script:h}/$i/${${script:t}/??_/} - if test -f $specific_script - then - __debug -n "$i/${${specific_script:t:r}/??_/}... "; - source $specific_script - __debug - fi - if test -f $specific_script.gpg - then - __debug -n "$i/${${specific_script:t:r}/??_/} [CRYPTED]... "; - eval $(gpg --quiet --decrypt $specific_script.gpg) - __debug - fi - done + recurse_load ${${script:t}/??_/} ${script:h} done fi -- cgit v1.2.3