From 2adfbb0de333b810fce0a9ca331d7fd7001c9198 Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Wed, 28 Dec 2022 10:46:29 -0500 Subject: [PATCH 1/3] Fix #72: mkdir for datafile if necessary --- zsh-z.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-z.plugin.zsh b/zsh-z.plugin.zsh index 59f889e..8c0e23c 100644 --- a/zsh-z.plugin.zsh +++ b/zsh-z.plugin.zsh @@ -161,7 +161,7 @@ zshz() { # Make sure that the datafile exists before attempting to read it or lock it # for writing - [[ -f $datafile ]] || touch "$datafile" + [[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" } # Bail if we don't own the datafile and $ZSHZ_OWNER is not set [[ -z ${ZSHZ_OWNER:-${_Z_OWNER}} && -f $datafile && ! -O $datafile ]] && From 86cda3bbb4c589bf8a453101f5162cea35451e01 Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Wed, 4 Jan 2023 11:35:55 -0500 Subject: [PATCH 2/3] Use default directory if ZSHZ_DATA set w/o one --- zsh-z.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zsh-z.plugin.zsh b/zsh-z.plugin.zsh index 8c0e23c..ee74acf 100644 --- a/zsh-z.plugin.zsh +++ b/zsh-z.plugin.zsh @@ -150,8 +150,10 @@ zshz() { local -a lines # Allow the user to specify the datafile name in $ZSHZ_DATA (default: ~/.z) - # If the datafile is a symlink, it gets dereferenced + # If the datafile is a symlink, it gets dereferenced. If no directory was + # specified, default to zsh home. local datafile=${${ZSHZ_DATA:-${_Z_DATA:-${HOME}/.z}}:A} + [[ "${datafile:h}" != '.' ]] || datafile="${ZDOTDIR:-$HOME}/$datafile" # If the datafile is a directory, print a warning and exit if [[ -d $datafile ]]; then From 91c4ca66fbface313e5e1626ead66a254b170994 Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Thu, 19 Jan 2023 16:39:20 -0500 Subject: [PATCH 3/3] Error if ZSHZ_DATA improperly set --- zsh-z.plugin.zsh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/zsh-z.plugin.zsh b/zsh-z.plugin.zsh index ee74acf..26575a4 100644 --- a/zsh-z.plugin.zsh +++ b/zsh-z.plugin.zsh @@ -149,11 +149,19 @@ zshz() { local REPLY local -a lines - # Allow the user to specify the datafile name in $ZSHZ_DATA (default: ~/.z) - # If the datafile is a symlink, it gets dereferenced. If no directory was - # specified, default to zsh home. - local datafile=${${ZSHZ_DATA:-${_Z_DATA:-${HOME}/.z}}:A} - [[ "${datafile:h}" != '.' ]] || datafile="${ZDOTDIR:-$HOME}/$datafile" + # Allow the user to specify a custom datafile in $ZSHZ_DATA (or legacy $_Z_DATA) + local custom_datafile="${ZSHZ_DATA:-$_Z_DATA}" + + # If a datafile was provided as a standalone file without a directory path + # print a warning and exit + if [[ -n ${custom_datafile} && ${custom_datafile} != */* ]]; then + print "ERROR: You configured a custom Zsh-z datafile (${custom_datafile}), but have not specified its directory." >&2 + exit + fi + + # If the user specified a datafile, use that or default to ~/.z + # If the datafile is a symlink, it gets dereferenced + local datafile=${${custom_datafile:-$HOME/.z}:A} # If the datafile is a directory, print a warning and exit if [[ -d $datafile ]]; then