From e9db94a1e2a72ae51e476cbc372ca774f3c65125 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 18 Dec 2008 09:51:39 +0100 Subject: Fixed xsource to preserve typeset'ed parameters. A quite ugly solution, but the best I could think of (and still better than [[ -r $file ]] && source $file or source $file &> /dev/null, IMHO) --- etc/functions/xsource | 16 ++++++++++------ etc/rc | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'etc') diff --git a/etc/functions/xsource b/etc/functions/xsource index 2546965..b5cd904 100755 --- a/etc/functions/xsource +++ b/etc/functions/xsource @@ -1,8 +1,12 @@ ## vim:ft=zsh -# Note: This function's behaviour differs hrom source. -# With source, parameters declared local are available to the sourcing script. -# With xsource, parameters declared local will NOT be available. -# Keep that in mind when using this function -if [[ -r $1 ]] { - source $1 +# Since source in a function makes typeset'ed parameters local +# (which is not what we want), we use a combination of functions +# and aliases here: +# autoload xsource; alias x_source='source $xsource_files; unset xsource_files' +# xsource file anotherfile && x_source +typeset file +(( ${#*} )) && unset xsource_files +for file in $*; { + [[ -r $file ]] && xsource_files=($xsource_files $file) } +(( ${#xsource_files} )) || return 1 diff --git a/etc/rc b/etc/rc index f29a547..aac5cfa 100644 --- a/etc/rc +++ b/etc/rc @@ -10,6 +10,7 @@ uname=$(uname) alias 'linux:'='[[ $uname = Linux ]] &&' alias 'openbsd:'='[[ $uname = OpenBSD ]] &&' +alias x_source='source $xsource_files; unset xsource_files' ## include the actual config source $ZDIR/options @@ -26,9 +27,9 @@ source $ZDIR/alias/font source $ZDIR/alias/default source $ZDIR/alias/global source $ZDIR/alias/short -xsource $ZDIR/../provided/includes -xsource $ZDIR/local -xsource $HOME/var/tmp/envstore-raw-$UID +xsource $ZDIR/../provided/includes $ZDIR/local \ + $HOME/var/tmp/envstore-raw-$UID && +x_source source $ZDIR/completion (( ZPROFILE )) && source $ZDIR/profile @@ -43,6 +44,7 @@ chpwd ## cleanup unalias 'linux:' unalias 'openbsd:' +unalias x_source unfunction check_com unfunction xexport unfunction xsource -- cgit v1.2.3