From f6bb75579f57a26d2a7f6db7e42421e6768edae5 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sat, 10 Jun 2017 20:54:22 -0300 Subject: [PATCH] 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 --- init.zsh | 12 ++++++------ modules/custom/functions/example_function | 2 +- modules/debug/functions/trace-zim | 4 ++-- templates/zlogin | 2 +- templates/zshrc | 7 +++++-- tools/zim_build_cache | 2 +- tools/zim_clean_cache | 2 +- tools/zim_info | 2 +- tools/zim_issue | 4 ++-- tools/zim_remove | 2 +- tools/zim_reset | 2 +- tools/zim_update | 2 +- 12 files changed, 23 insertions(+), 20 deletions(-) diff --git a/init.zsh b/init.zsh index b510a30..e692f94 100755 --- a/init.zsh +++ b/init.zsh @@ -9,7 +9,7 @@ if ! is-at-least 5.2; then fi # Define zim location -ZIM="${ZDOTDIR:-${HOME}}/.zim" +(( ! ${+ZIM_HOME} )) && ZIM_HOME="${ZDOTDIR:-${HOME}}/.zim" # Source user configuration if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then @@ -20,9 +20,9 @@ load_zim_module() { local wanted_module for wanted_module (${zmodules}); do - if [[ -s "${ZIM}/modules/${wanted_module}/init.zsh" ]]; then - source "${ZIM}/modules/${wanted_module}/init.zsh" - elif [[ ! -d "${ZIM}/modules/${wanted_module}" ]]; then + if [[ -s "${ZIM_HOME}/modules/${wanted_module}/init.zsh" ]]; then + source "${ZIM_HOME}/modules/${wanted_module}/init.zsh" + elif [[ ! -d "${ZIM_HOME}/modules/${wanted_module}" ]]; then print "No such module \"${wanted_module}\"." >&2 fi done @@ -33,12 +33,12 @@ load_zim_function() { local mod_function # 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 { 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} done } diff --git a/modules/custom/functions/example_function b/modules/custom/functions/example_function index 752e7df..fc78a6f 100644 --- a/modules/custom/functions/example_function +++ b/modules/custom/functions/example_function @@ -1,4 +1,4 @@ # this is an example function # 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!" diff --git a/modules/debug/functions/trace-zim b/modules/debug/functions/trace-zim index 4b9403a..65d3dee 100644 --- a/modules/debug/functions/trace-zim +++ b/modules/debug/functions/trace-zim @@ -43,9 +43,9 @@ cp ${ZDOTDIR:-${HOME}}/.zshrc /tmp/ztrace/.zshrc.orig cp ${ZDOTDIR:-${HOME}}/.zimrc /tmp/ztrace/.zimrc # rsync will allow us to not have to copy the .git folder; use if available if (( ${+commands[rsync]} )); then - rsync -az --exclude .git ${ZDOTDIR:-${HOME}}/.zim /tmp/ztrace/ + rsync -az --exclude .git ${ZIM_HOME} /tmp/ztrace/ else - cp -R ${ZDOTDIR:-${HOME}}/.zim /tmp/ztrace/ + cp -R ${ZIM_HOME} /tmp/ztrace/ fi # create a modified .zshrc to produce a trace log diff --git a/templates/zlogin b/templates/zlogin index f05b263..bffb942 100644 --- a/templates/zlogin +++ b/templates/zlogin @@ -17,7 +17,7 @@ fi } - zim_mods=${ZDOTDIR:-${HOME}}/.zim/modules + zim_mods=${ZIM_HOME}/modules setopt EXTENDED_GLOB # zcompile the completion cache; siginificant speedup. diff --git a/templates/zshrc b/templates/zshrc index e640dcc..0f9665c 100644 --- a/templates/zshrc +++ b/templates/zshrc @@ -4,8 +4,11 @@ # User configuration sourced by interactive shells # +# Change default zim location +export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim + # Source zim -if [[ -s ${ZDOTDIR:-${HOME}}/.zim/init.zsh ]]; then - source ${ZDOTDIR:-${HOME}}/.zim/init.zsh +if [[ -s ${ZIM_HOME}/init.zsh ]]; then + source ${ZIM_HOME}/init.zsh fi diff --git a/tools/zim_build_cache b/tools/zim_build_cache index 3e747e4..15d3b8f 100644 --- a/tools/zim_build_cache +++ b/tools/zim_build_cache @@ -2,4 +2,4 @@ # zim_build_cache - rebuilds the zim cache # -source ${ZDOTDIR:-${HOME}}/.zim/templates/zlogin +source ${ZIM_HOME}/templates/zlogin diff --git a/tools/zim_clean_cache b/tools/zim_clean_cache index cc62215..dd3ea7c 100644 --- a/tools/zim_clean_cache +++ b/tools/zim_clean_cache @@ -2,7 +2,7 @@ # 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} print 'To rebuild the completion cache, please restart your terminal' diff --git a/tools/zim_info b/tools/zim_info index 856d2b4..1c00230 100644 --- a/tools/zim_info +++ b/tools/zim_info @@ -2,7 +2,7 @@ # 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 "Zsh version: $(command zsh --version)" diff --git a/tools/zim_issue b/tools/zim_issue index 5d99cea..bff3d6f 100644 --- a/tools/zim_issue +++ b/tools/zim_issue @@ -24,7 +24,7 @@ if ! waiter_func; then fi # for convenience, this is our new home -cd ${ZDOTDIR:-${HOME}}/.zim +cd ${ZIM_HOME} # collect sys info 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 [[ -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 '```' print $(command git diff) diff --git a/tools/zim_remove b/tools/zim_remove index 925f9b5..a19b42d 100644 --- a/tools/zim_remove +++ b/tools/zim_remove @@ -10,4 +10,4 @@ sed '/# The following code helps/,/) &!/d' ${ZDOTDIR:-${HOME}}/.zlogin rm -f ${ZDOTDIR:-${HOME}}/.zimrc # not forcing this one, as it is recursive. It's possible something went wrong. -rm -r ${ZDOTDIR:-${HOME}}/.zim/ +rm -r ${ZIM_HOME} diff --git a/tools/zim_reset b/tools/zim_reset index 2357fc0..f1e33b7 100644 --- a/tools/zim_reset +++ b/tools/zim_reset @@ -2,5 +2,5 @@ # zim_reset - resets the zim repository to latest commit # -cd ${ZDOTDIR:-${HOME}}/.zim +cd ${ZIM_HOME} git reset --hard diff --git a/tools/zim_update b/tools/zim_update index 5f3f73e..38c9e38 100644 --- a/tools/zim_update +++ b/tools/zim_update @@ -2,7 +2,7 @@ # 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 git remote update -p