diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2008-12-18 09:51:39 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2008-12-18 09:51:39 +0100 |
commit | e9db94a1e2a72ae51e476cbc372ca774f3c65125 (patch) | |
tree | b53916916d774f1da90959547d1f6a3bbf41127c /etc/functions | |
parent | c56315bc005e964c3509d6f8439e4eebea446d00 (diff) |
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)
Diffstat (limited to 'etc/functions')
-rwxr-xr-x | etc/functions/xsource | 16 |
1 files changed, 10 insertions, 6 deletions
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 |