Allow arbitrary ZIM location with ZIM_HOME
This change allow arbitrary Zim location path by setting a new environment variable, ZIM_HOME. If the user does not set it, Zim falls back to the old "${ZDOTDIR:-${HOME}}/.zim" location. Closes #203
This commit is contained in:
parent
96c474978e
commit
f6bb75579f
12 changed files with 23 additions and 20 deletions
12
init.zsh
12
init.zsh
|
@ -9,7 +9,7 @@ if ! is-at-least 5.2; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define zim location
|
# Define zim location
|
||||||
ZIM="${ZDOTDIR:-${HOME}}/.zim"
|
(( ! ${+ZIM_HOME} )) && ZIM_HOME="${ZDOTDIR:-${HOME}}/.zim"
|
||||||
|
|
||||||
# Source user configuration
|
# Source user configuration
|
||||||
if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then
|
if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then
|
||||||
|
@ -20,9 +20,9 @@ load_zim_module() {
|
||||||
local wanted_module
|
local wanted_module
|
||||||
|
|
||||||
for wanted_module (${zmodules}); do
|
for wanted_module (${zmodules}); do
|
||||||
if [[ -s "${ZIM}/modules/${wanted_module}/init.zsh" ]]; then
|
if [[ -s "${ZIM_HOME}/modules/${wanted_module}/init.zsh" ]]; then
|
||||||
source "${ZIM}/modules/${wanted_module}/init.zsh"
|
source "${ZIM_HOME}/modules/${wanted_module}/init.zsh"
|
||||||
elif [[ ! -d "${ZIM}/modules/${wanted_module}" ]]; then
|
elif [[ ! -d "${ZIM_HOME}/modules/${wanted_module}" ]]; then
|
||||||
print "No such module \"${wanted_module}\"." >&2
|
print "No such module \"${wanted_module}\"." >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -33,12 +33,12 @@ load_zim_function() {
|
||||||
local mod_function
|
local mod_function
|
||||||
|
|
||||||
# autoload searches fpath for function locations; add enabled module function paths
|
# autoload searches fpath for function locations; add enabled module function paths
|
||||||
fpath=(${${zmodules}:+${ZIM}/modules/${^zmodules}/functions(/FN)} ${fpath})
|
fpath=(${${zmodules}:+${ZIM_HOME}/modules/${^zmodules}/functions(/FN)} ${fpath})
|
||||||
|
|
||||||
function {
|
function {
|
||||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||||
|
|
||||||
for mod_function in ${ZIM}/modules/${^zmodules}/functions/${~function_glob}; do
|
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/${~function_glob}; do
|
||||||
autoload -Uz ${mod_function}
|
autoload -Uz ${mod_function}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# this is an example function
|
# this is an example function
|
||||||
# running 'example_function' in a zsh session will execute the code below
|
# running 'example_function' in a zsh session will execute the code below
|
||||||
|
|
||||||
print "executed example function: ${ZDOTDIR:-${HOME}}/modules/custom/functions/example_function!"
|
print "executed example function: ${ZIM_HOME}/modules/custom/functions/example_function!"
|
||||||
|
|
|
@ -43,9 +43,9 @@ cp ${ZDOTDIR:-${HOME}}/.zshrc /tmp/ztrace/.zshrc.orig
|
||||||
cp ${ZDOTDIR:-${HOME}}/.zimrc /tmp/ztrace/.zimrc
|
cp ${ZDOTDIR:-${HOME}}/.zimrc /tmp/ztrace/.zimrc
|
||||||
# rsync will allow us to not have to copy the .git folder; use if available
|
# rsync will allow us to not have to copy the .git folder; use if available
|
||||||
if (( ${+commands[rsync]} )); then
|
if (( ${+commands[rsync]} )); then
|
||||||
rsync -az --exclude .git ${ZDOTDIR:-${HOME}}/.zim /tmp/ztrace/
|
rsync -az --exclude .git ${ZIM_HOME} /tmp/ztrace/
|
||||||
else
|
else
|
||||||
cp -R ${ZDOTDIR:-${HOME}}/.zim /tmp/ztrace/
|
cp -R ${ZIM_HOME} /tmp/ztrace/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# create a modified .zshrc to produce a trace log
|
# create a modified .zshrc to produce a trace log
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
zim_mods=${ZDOTDIR:-${HOME}}/.zim/modules
|
zim_mods=${ZIM_HOME}/modules
|
||||||
setopt EXTENDED_GLOB
|
setopt EXTENDED_GLOB
|
||||||
|
|
||||||
# zcompile the completion cache; siginificant speedup.
|
# zcompile the completion cache; siginificant speedup.
|
||||||
|
|
|
@ -4,8 +4,11 @@
|
||||||
# User configuration sourced by interactive shells
|
# User configuration sourced by interactive shells
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Change default zim location
|
||||||
|
export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
|
||||||
|
|
||||||
# Source zim
|
# Source zim
|
||||||
if [[ -s ${ZDOTDIR:-${HOME}}/.zim/init.zsh ]]; then
|
if [[ -s ${ZIM_HOME}/init.zsh ]]; then
|
||||||
source ${ZDOTDIR:-${HOME}}/.zim/init.zsh
|
source ${ZIM_HOME}/init.zsh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
# zim_build_cache - rebuilds the zim cache
|
# zim_build_cache - rebuilds the zim cache
|
||||||
#
|
#
|
||||||
|
|
||||||
source ${ZDOTDIR:-${HOME}}/.zim/templates/zlogin
|
source ${ZIM_HOME}/templates/zlogin
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# zim_clean_cache - removes all zcompiled files
|
# zim_clean_cache - removes all zcompiled files
|
||||||
#
|
#
|
||||||
|
|
||||||
find ${ZDOTDIR:-${HOME}}/.zim/ -iname '*.zwc' | xargs rm
|
find ${ZIM_HOME} -iname '*.zwc' | xargs rm
|
||||||
rm -f ${ZDOTDIR:-${HOME}}/.{zshrc.zwc,zcompdump,zcompdump.zwc}
|
rm -f ${ZDOTDIR:-${HOME}}/.{zshrc.zwc,zcompdump,zcompdump.zwc}
|
||||||
|
|
||||||
print 'To rebuild the completion cache, please restart your terminal'
|
print 'To rebuild the completion cache, please restart your terminal'
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# zim_info - prints zim and system info
|
# zim_info - prints zim and system info
|
||||||
#
|
#
|
||||||
|
|
||||||
cd ${ZDOTDIR:-${HOME}}/.zim
|
cd ${ZIM_HOME}
|
||||||
|
|
||||||
print "Zim commit ref: $(command git rev-parse --short HEAD)"
|
print "Zim commit ref: $(command git rev-parse --short HEAD)"
|
||||||
print "Zsh version: $(command zsh --version)"
|
print "Zsh version: $(command zsh --version)"
|
||||||
|
|
|
@ -24,7 +24,7 @@ if ! waiter_func; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# for convenience, this is our new home
|
# for convenience, this is our new home
|
||||||
cd ${ZDOTDIR:-${HOME}}/.zim
|
cd ${ZIM_HOME}
|
||||||
|
|
||||||
# collect sys info
|
# collect sys info
|
||||||
git_dirty=$(command git status --porcelain 2>/dev/null | tail -n1)
|
git_dirty=$(command git status --porcelain 2>/dev/null | tail -n1)
|
||||||
|
@ -64,7 +64,7 @@ done
|
||||||
|
|
||||||
# if we have a dirty git, report it
|
# if we have a dirty git, report it
|
||||||
if [[ -n ${git_dirty} ]]; then
|
if [[ -n ${git_dirty} ]]; then
|
||||||
print "${ZDOTDIR:-${HOME}}/.zim has a dirty git working tree."
|
print "${ZIM_HOME} has a dirty git working tree."
|
||||||
print "here is the diff:"
|
print "here is the diff:"
|
||||||
print '```'
|
print '```'
|
||||||
print $(command git diff)
|
print $(command git diff)
|
||||||
|
|
|
@ -10,4 +10,4 @@ sed '/# The following code helps/,/) &!/d' ${ZDOTDIR:-${HOME}}/.zlogin
|
||||||
rm -f ${ZDOTDIR:-${HOME}}/.zimrc
|
rm -f ${ZDOTDIR:-${HOME}}/.zimrc
|
||||||
|
|
||||||
# not forcing this one, as it is recursive. It's possible something went wrong.
|
# not forcing this one, as it is recursive. It's possible something went wrong.
|
||||||
rm -r ${ZDOTDIR:-${HOME}}/.zim/
|
rm -r ${ZIM_HOME}
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
# zim_reset - resets the zim repository to latest commit
|
# zim_reset - resets the zim repository to latest commit
|
||||||
#
|
#
|
||||||
|
|
||||||
cd ${ZDOTDIR:-${HOME}}/.zim
|
cd ${ZIM_HOME}
|
||||||
git reset --hard
|
git reset --hard
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# zim_update - update the zim repository
|
# zim_update - update the zim repository
|
||||||
#
|
#
|
||||||
|
|
||||||
cd ${ZDOTDIR:-${HOME}/.zim}
|
cd ${ZIM_HOME}
|
||||||
|
|
||||||
# this is the cleanest way I know how to update a repository
|
# this is the cleanest way I know how to update a repository
|
||||||
git remote update -p
|
git remote update -p
|
||||||
|
|
Loading…
Reference in a new issue