summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues.hiegel@qosmos.com>2014-10-23 16:14:51 +0200
committerHugues Hiegel <hugues.hiegel@qosmos.com>2014-10-23 16:14:51 +0200
commita4b31794d10bef9be211f661898bd012cf4e5566 (patch)
tree59a759a69826a39a0829d396695b6f3da263f63b
parentd433174945ec2d7374e32490369a673b1ba61514 (diff)
[.zshrc] recursive call of specific scripts
Specific scripts loop rewritten in a much cleaner way.
-rw-r--r--zshrc73
1 files 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