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
modules
autoloader
loader.zsh
zshrc

View file

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

View file

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

22
zshrc
View file

@ -13,8 +13,22 @@ setopt short_loops
setopt cdable_vars setopt cdable_vars
# autoload completions # autoload completions
fpath+=( "${ZDOTDIR:-/etc/zsh}/compdef" ) fpath+=( "${ZDOTDIR:+ZDOTDIR}/compdef" )
autoload -U ${ZDOTDIR:-/etc/zsh}/compdef/*(:t) 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 bindkey -v
@ -29,9 +43,9 @@ function exists { command -v "$@" >/dev/null }
stty -ixon 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 . $i
done done