Fix handling of ZDOTDIR variable

This commit is contained in:
Alexander Gehrke (crater2150) 2016-07-25 13:48:52 +02:00
parent 5a57b66d11
commit 345d95999f
3 changed files with 75 additions and 31 deletions

View file

@ -7,25 +7,38 @@
# Lets you load custom functions and zle widgets split into single files.
#
# zle widgets are stored in the "widgets" folder in your configuration directory
# (set with $ZDOTDIR, see manpage. defaults to /etc/zsh)
# (set with $ZDOTDIR, see manpage). The widgets in /etc/zsh/widgets are also
# considered.
#
# functions are stored in the "functions" folder analogous.
#
ZWIDGETPATH=${ZWIDGETPATH:-"${ZDOTDIR:-/etc/zsh}/widgets"}
ZFUNCTIONPATH=${ZFUNCTIONPATH:-"${ZDOTDIR:-/etc/zsh}/functions"}
fpath+=( "${ZWIDGETPATH}" )
fpath+=( "${ZFUNCTIONPATH}" )
if [[ -z $ZWIDGETPATH ]]; then
ZWIDGETPATH=( ${ZDOTDIR:+$ZDOTDIR/widgets} )
[[ -d /etc/zsh/widgets ]] && ZWIDGETPATH+=/etc/zsh/widgets
fi
if [ -d $ZWIDGETPATH ]; then
for i in $ZWIDGETPATH/*(N:t); do
if [[ -z $ZFUNCTIONPATH ]]; then
ZFUNCTIONPATH=( ${ZDOTDIR:+$ZDOTDIR/functions} )
[[ -d /etc/zsh/functions ]] && ZFUNCTIONPATH+=/etc/zsh/functions
fi
fpath+=(${ZWIDGETPATH})
fpath+=(${ZFUNCTIONPATH})
for dir in $ZWIDGETPATH; do
if [ -d $dir ]; then
for i in $dir/*~*.zwc(N:t); do
autoload -Uz $i
zle -N $i
done
fi
fi
done
if [ -d $ZFUNCTIONPATH ]; then
for i in $ZFUNCTIONPATH/*(N:t); do
for dir in $ZFUNCTIONPATH; do
if [ -d $dir ]; then
for i in $dir/*~*.zwc(N:t); do
autoload -Uz $i && $i
done
fi
fi
done

View file

@ -21,8 +21,23 @@
#################################
# Path to module directory
ZMODPATH=${ZMODPATH:-"${ZDOTDIR:-/etc/zsh}/modules"}
. $ZMODPATH/helpers.zsh
if [[ -z $ZMODPATH ]]; then
ZMODPATH=( ${ZDOTDIR:+$ZDOTDIR/modules} )
[[ -d /etc/zsh/modules ]] && ZMODPATH+=/etc/zsh/modules
fi
local mod_path() {
for dir in $ZMODPATH; do
if [[ -e $dir/$1 ]]; then
echo "$dir/$1"
return 0
fi
done
return 1
}
. $(mod_path helpers.zsh)
errdetails=""
modqueue=( )
@ -41,7 +56,7 @@ modqueue=( )
#
mod_queue() {
local module="$1"
local modsource="$ZMODPATH/$module"
local modsource=$(mod_path $module)
if ! mod_exists "$module" ; then
if [[ "$2" == "is_dep" ]]; then
@ -65,7 +80,7 @@ mod_queue() {
}
mod_exists() {
[ -e "$ZMODPATH/$module" ]
mod_path "$1" &> /dev/null
}
# Checks for module dependencies
@ -132,8 +147,8 @@ mod_check_dep() {
mod_load() {
local MPATH
for module in "${(@)modqueue}"; do
MPATH="$ZMODPATH/$module"
[ -e "$ZMODPATH/$module/init" ] && . "$ZMODPATH/$module/init"
MPATH=$(mod_path $module)
[ -e "$(mod_path $module)/init" ] && . "$(mod_path $module)/init"
done
}
@ -146,15 +161,17 @@ mod_init() {
if [ -n "$ZMODLOAD_ONLY" ]; then
for module in "${(@)ZMODLOAD_ONLY}"; do
[ -d "$ZMODPATH/$module" ] && mod_queue "$module"
[ -d "$(mod_path $module)" ] && mod_queue "$module"
done
else
for module in $ZMODPATH/*(/N); do
for moddir in $ZMODPATH; do
for module in $moddir/*(/N); do
if [ -z "$ZMODLOAD_BLACKLIST" ] \
|| ! in_array ${module:t} ${(@)ZMODLOAD_BLACKLIST}; then
mod_queue "${module:t}"
fi
done
done
fi
mod_load

22
zshrc
View file

@ -13,8 +13,22 @@ setopt short_loops
setopt cdable_vars
# autoload completions
fpath+=( "${ZDOTDIR:-/etc/zsh}/compdef" )
autoload -U ${ZDOTDIR:-/etc/zsh}/compdef/*(:t)
fpath+=( "${ZDOTDIR:+ZDOTDIR}/compdef" )
fpath+=( "/etc/zsh/compdef" )
autoload -U /etc/zsh/compdef/*(:t)
if [[ -d $ZDOTDIR/compdef ]]; then
autoload -U /etc/zsh/compdef/*(N:t)
fi
# get a file from ZDOTDIR, return file in /etc/zsh if it does not exist
zdotfile() {
if [[ -e $ZDOTDIR/$1 ]]; then
echo $ZDOTDIR/$1
else
echo /etc/zsh/$1
fi
}
bindkey -v
@ -29,9 +43,9 @@ function exists { command -v "$@" >/dev/null }
stty -ixon
. ${ZDOTDIR:-/etc/zsh}/modules/loader.zsh && mod_init
. $(zdotfile modules/loader.zsh) && mod_init
for i in ${ZDOTDIR:-/etc/zsh}/aliases/*~${ZDOTDIR:-/etc/zsh}/aliases/*.zwc; do
for i in ${ZDOTDIR:+ZDOTDIR/aliases/*~*.zwc(N)} /etc/zsh/aliases/*~*.zwc(N); do
. $i
done