Use ZIM_DATA_DIR and install to XDG_DATA_HOME by default
This commit is contained in:
parent
9eaba9a3a3
commit
947f96c04c
14 changed files with 34 additions and 27 deletions
|
@ -42,13 +42,13 @@ Installing Zim is easy. If you have a different shell framework installed (like
|
||||||
|
|
||||||
1. In a Zsh shell, clone the repository:
|
1. In a Zsh shell, clone the repository:
|
||||||
```
|
```
|
||||||
git clone --recursive https://github.com/Eriner/zim.git ${ZDOTDIR:-${HOME}}/.zim
|
git clone --recursive https://github.com/Eriner/zim.git "${XDG_DATA_HOME:-"${HOME}/.local/share"}/zim"
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Paste this into your terminal to prepend the initialization templates to your configs:
|
2. Paste this into your terminal to prepend the initialization templates to your configs:
|
||||||
```
|
```
|
||||||
setopt EXTENDED_GLOB
|
setopt EXTENDED_GLOB
|
||||||
for template_file ( ${ZDOTDIR:-${HOME}}/.zim/templates/* ); do
|
for template_file ( ${ZIM_DATA_DIR}/templates/* ); do
|
||||||
user_file="${ZDOTDIR:-${HOME}}/.${template_file:t}"
|
user_file="${ZDOTDIR:-${HOME}}/.${template_file:t}"
|
||||||
touch ${user_file}
|
touch ${user_file}
|
||||||
( print -rn "$(<${template_file})$(<${user_file})" >! ${user_file} ) 2>/dev/null
|
( print -rn "$(<${template_file})$(<${user_file})" >! ${user_file} ) 2>/dev/null
|
||||||
|
@ -81,7 +81,7 @@ For more information about the `zmanage` tool, see the [meta module][meta-module
|
||||||
Uninstalling
|
Uninstalling
|
||||||
------------
|
------------
|
||||||
|
|
||||||
The best way to remove zim is to manually delete `~/.zim`, `~/.zimrc`, and
|
The best way to remove zim is to manually delete `~/.local/share/zim`, `~/.zimrc`, and
|
||||||
remove the initialization lines from your `~/.zshrc`.
|
remove the initialization lines from your `~/.zshrc`.
|
||||||
|
|
||||||
However, there are some **experimental** convenience functions to remove zim:
|
However, there are some **experimental** convenience functions to remove zim:
|
||||||
|
|
19
init.zsh
19
init.zsh
|
@ -9,7 +9,14 @@ if ! is-at-least 5.2; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define zim location
|
# Define zim location
|
||||||
(( ! ${+ZIM_HOME} )) && export ZIM_HOME="${ZDOTDIR:-${HOME}}/.zim"
|
(( ! ${+ZIM_DATA_DIR} )) && \
|
||||||
|
if [[ -d "${XDG_DATA_HOME:-"${HOME}/.local/share"}/zim" ]]; then
|
||||||
|
export ZIM_DATA_DIR="${XDG_DATA_HOME:-"${HOME}/.local/share"}/zim"
|
||||||
|
elif [[ -d "${ZDOTDIR:-${HOME}}/.zim" ]]; then
|
||||||
|
export ZIM_DATA_DIR="${ZDOTDIR:-${HOME}}/.zim"
|
||||||
|
else
|
||||||
|
export ZIM_DATA_DIR="${XDG_DATA_HOME:-"${HOME}/.local/share"}/zim"
|
||||||
|
fi
|
||||||
|
|
||||||
# Source user configuration
|
# Source user configuration
|
||||||
if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then
|
if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then
|
||||||
|
@ -20,9 +27,9 @@ load_zim_module() {
|
||||||
local wanted_module
|
local wanted_module
|
||||||
|
|
||||||
for wanted_module (${zmodules}); do
|
for wanted_module (${zmodules}); do
|
||||||
if [[ -s "${ZIM_HOME}/modules/${wanted_module}/init.zsh" ]]; then
|
if [[ -s "${ZIM_DATA_DIR}/modules/${wanted_module}/init.zsh" ]]; then
|
||||||
source "${ZIM_HOME}/modules/${wanted_module}/init.zsh"
|
source "${ZIM_DATA_DIR}/modules/${wanted_module}/init.zsh"
|
||||||
elif [[ ! -d "${ZIM_HOME}/modules/${wanted_module}" ]]; then
|
elif [[ ! -d "${ZIM_DATA_DIR}/modules/${wanted_module}" ]]; then
|
||||||
print "No such module \"${wanted_module}\"." >&2
|
print "No such module \"${wanted_module}\"." >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -33,12 +40,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_HOME}/modules/${^zmodules}/functions(/FN)} ${fpath})
|
fpath=(${${zmodules}:+${ZIM_DATA_DIR}/modules/${^zmodules}/functions(/FN)} ${fpath})
|
||||||
|
|
||||||
function {
|
function {
|
||||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||||
|
|
||||||
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/${~function_glob}; do
|
for mod_function in ${ZIM_DATA_DIR}/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: ${ZIM_HOME}/modules/custom/functions/example_function!"
|
print "executed example function: ${ZIM_DATA_DIR}/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 ${ZIM_HOME} /tmp/ztrace/
|
rsync -az --exclude .git ${ZIM_DATA_DIR} /tmp/ztrace/
|
||||||
else
|
else
|
||||||
cp -R ${ZIM_HOME} /tmp/ztrace/
|
cp -R ${ZIM_DATA_DIR} /tmp/ztrace/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# create a modified .zshrc to produce a trace log
|
# create a modified .zshrc to produce a trace log
|
||||||
|
|
|
@ -16,7 +16,7 @@ if (( ${#} != 1 )); then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local tools
|
local tools
|
||||||
tools="${ZIM_HOME}/tools"
|
tools="${ZIM_DATA_DIR}/tools"
|
||||||
|
|
||||||
case ${1} in
|
case ${1} in
|
||||||
update) zsh ${tools}/zim_update
|
update) zsh ${tools}/zim_update
|
||||||
|
@ -33,7 +33,7 @@ case ${1} in
|
||||||
;;
|
;;
|
||||||
reset) zsh ${tools}/zim_reset
|
reset) zsh ${tools}/zim_reset
|
||||||
;;
|
;;
|
||||||
debug) zsh ${ZIM_HOME}/modules/debug/functions/trace-zim
|
debug) zsh ${ZIM_DATA_DIR}/modules/debug/functions/trace-zim
|
||||||
;;
|
;;
|
||||||
*) print ${usage}
|
*) print ${usage}
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
zim_mods=${ZIM_HOME}/modules
|
zim_mods=${ZIM_DATA_DIR}/modules
|
||||||
setopt EXTENDED_GLOB
|
setopt EXTENDED_GLOB
|
||||||
|
|
||||||
# zcompile the completion cache; siginificant speedup.
|
# zcompile the completion cache; siginificant speedup.
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
# User configuration sourced by interactive shells
|
# User configuration sourced by interactive shells
|
||||||
#
|
#
|
||||||
|
|
||||||
# Change default zim location
|
# Define zim location
|
||||||
export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
|
(( ! ${+ZIM_DATA_DIR} )) && export ZIM_DATA_DIR="${XDG_DATA_HOME:-"${HOME}/.local/share"}/zim"
|
||||||
|
|
||||||
# Source zim
|
# Source zim
|
||||||
if [[ -s ${ZIM_HOME}/init.zsh ]]; then
|
if [[ -s "${ZIM_DATA_DIR}/init.zsh" ]]; then
|
||||||
source ${ZIM_HOME}/init.zsh
|
source "${ZIM_DATA_DIR}/init.zsh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
# zim_build_cache - rebuilds the zim cache
|
# zim_build_cache - rebuilds the zim cache
|
||||||
#
|
#
|
||||||
|
|
||||||
source ${ZIM_HOME}/templates/zlogin
|
source ${ZIM_DATA_DIR}/templates/zlogin
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# zim_clean_cache - removes all zcompiled files
|
# zim_clean_cache - removes all zcompiled files
|
||||||
#
|
#
|
||||||
|
|
||||||
find ${ZIM_HOME} -iname '*.zwc' | xargs rm
|
find ${ZIM_DATA_DIR} -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 ${ZIM_HOME}
|
cd ${ZIM_DATA_DIR}
|
||||||
|
|
||||||
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 ${ZIM_HOME}
|
cd ${ZIM_DATA_DIR}
|
||||||
|
|
||||||
# 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 "${ZIM_HOME} has a dirty git working tree."
|
print "${ZIM_DATA_DIR} 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 ${ZIM_HOME}
|
rm -r ${ZIM_DATA_DIR}
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
# zim_reset - resets the zim repository to latest commit
|
# zim_reset - resets the zim repository to latest commit
|
||||||
#
|
#
|
||||||
|
|
||||||
cd ${ZIM_HOME}
|
cd ${ZIM_DATA_DIR}
|
||||||
git reset --hard
|
git reset --hard
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# zim_update - update the zim repository
|
# zim_update - update the zim repository
|
||||||
#
|
#
|
||||||
|
|
||||||
cd ${ZIM_HOME}
|
cd ${ZIM_DATA_DIR}
|
||||||
|
|
||||||
# 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