added support for external modules
This commit is contained in:
parent
1bff61b902
commit
b62b482989
39
init.zsh
39
init.zsh
|
@ -20,15 +20,25 @@ else
|
|||
bindkey -e
|
||||
fi
|
||||
|
||||
# Map modules to dirs
|
||||
for zmodule in ${zmodules}; do
|
||||
dir=${${${zmodule%/}%.git}##*/}
|
||||
if [ -d ${ZIM_HOME}/modules/${dir} ]; then
|
||||
zmodule_dirs+=(${dir})
|
||||
else
|
||||
print "No such module \"${zmodule}\", run \"zmanage install\" to install missing modules" >&2
|
||||
fi
|
||||
done
|
||||
|
||||
# Autoload module functions
|
||||
() {
|
||||
local mod_function
|
||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||
|
||||
# autoload searches fpath for function locations; add enabled module function paths
|
||||
fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath})
|
||||
fpath=(${ZIM_HOME}/modules/${^zmodule_dirs}/functions(/FN) ${fpath})
|
||||
|
||||
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^(_*|prompt_*_setup|*.*)(-.N:t); do
|
||||
for mod_function in ${ZIM_HOME}/modules/${^zmodule_dirs}/functions/^(_*|prompt_*_setup|*.*)(-.N:t); do
|
||||
autoload -Uz ${mod_function}
|
||||
done
|
||||
}
|
||||
|
@ -37,26 +47,23 @@ fi
|
|||
() {
|
||||
local zmodule zmodule_dir zmodule_file
|
||||
|
||||
for zmodule in ${zmodules}; do
|
||||
for zmodule in ${zmodule_dirs}; do
|
||||
zmodule_dir=${ZIM_HOME}/modules/${zmodule}
|
||||
if [[ ! -d ${zmodule_dir} ]]; then
|
||||
print "No such module \"${zmodule}\"." >&2
|
||||
else
|
||||
for zmodule_file in ${zmodule_dir}/init.zsh \
|
||||
${zmodule_dir}/{,zsh-}${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}; do
|
||||
if [[ -f ${zmodule_file} ]]; then
|
||||
source ${zmodule_file}
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
for zmodule_file in ${zmodule_dir}/init.zsh \
|
||||
${zmodule_dir}/{,zsh-}${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}; do
|
||||
if [[ -f ${zmodule_file} ]]; then
|
||||
source ${zmodule_file}
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
zmanage() {
|
||||
local usage="zmanage [action]
|
||||
Actions:
|
||||
update Fetch and merge upstream zim commits if possible
|
||||
install Install zmodules
|
||||
update Update zim and zmodules
|
||||
info Print zim and system info
|
||||
issue Create a template for reporting an issue
|
||||
clean-cache Clean the zim cache
|
||||
|
@ -72,6 +79,8 @@ Actions:
|
|||
fi
|
||||
|
||||
case ${1} in
|
||||
install) zsh ${ZIM_HOME}/tools/zim_install
|
||||
;;
|
||||
update) zsh ${ZIM_HOME}/tools/zim_update
|
||||
;;
|
||||
info) zsh ${ZIM_HOME}/tools/zim_info
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# Source user configuration
|
||||
[[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc
|
||||
|
||||
# Install Modules
|
||||
mkdir -p ${ZIM_HOME}/modules
|
||||
for zmodule in ${zmodules}; do
|
||||
dir=$ZIM_HOME/modules/${${${zmodule%/}%.git}##*/}
|
||||
if [ -d ${dir} ]; then
|
||||
print "${zmodule} is already installed"
|
||||
else
|
||||
arr=("${(@s|/|)${zmodule%/}}")
|
||||
if [ ${#arr} = 1 ]; then
|
||||
repo="https://github.com/zimfw/${zmodule}"
|
||||
elif [ ${#arr} = 2 ]; then
|
||||
repo="https://github.com/${zmodule}"
|
||||
else
|
||||
repo=${zmodule}
|
||||
fi
|
||||
GIT_ASKPASS=/bin/echo git clone --recursive ${repo} ${dir} 2> /dev/null \
|
||||
&& print "${zmodule} got installed" || print "${repo} could not be installed"
|
||||
fi
|
||||
done
|
|
@ -9,3 +9,26 @@ git remote update -p
|
|||
git merge --ff-only @\{u\}
|
||||
# and update the submodules
|
||||
git submodule update --init --recursive
|
||||
|
||||
# Source user configuration
|
||||
[[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc
|
||||
|
||||
# Update zmodules
|
||||
for zmodule in ${zmodules}; do
|
||||
dir=${${${zmodule%/}%.git}##*/}
|
||||
if [ -d ${ZIM_HOME}/modules/${dir} ]; then
|
||||
|
||||
echo "\nUpdating ${zmodule} module."
|
||||
cd ${ZIM_HOME}/modules/${dir}
|
||||
|
||||
# update the modules repository
|
||||
git remote update -p
|
||||
git merge --ff-only @\{u\}
|
||||
|
||||
# and update the submodules
|
||||
git submodule update --init --recursive
|
||||
|
||||
else
|
||||
print "No such module \"${zmodule}\", run \"zmanage install\" to install missing modules" >&2
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue