diff --git a/README.md b/README.md index eddf787..ecfb971 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ Zsh-z has environment variables (they all begin with `ZSHZ_`) that change its be * `ZSHZ_CMD` changes the command name (default: `z`) * `ZSHZ_CD` specifies the default directory-changing command (default: `builtin cd`) * `ZSHZ_COMPLETION` can be `'frecent'` (default) or `'legacy'`, depending on whether you want your completion results sorted according to frecency or simply sorted alphabetically -* `ZSHZ_DATA` changes the database file (default: `~/.z`) +* `ZSHZ_DATA` changes the database file (default: `$ZDOTDIR/.z` falls back to `~/.z`) * `ZSHZ_ECHO` displays the new path name when changing directories (default: `0`) * `ZSHZ_EXCLUDE_DIRS` is an array of directories to keep out of the database (default: empty) * `ZSHZ_KEEP_DIRS` is an array of directories that should not be removed from the database, even if they are not currently available (useful when a drive is not always mounted) (default: empty) diff --git a/zsh-z.plugin.zsh b/zsh-z.plugin.zsh index 39b8322..f162046 100644 --- a/zsh-z.plugin.zsh +++ b/zsh-z.plugin.zsh @@ -56,7 +56,7 @@ # ZSHZ_CMD -> name of command (default: z) # ZSHZ_COMPLETION -> completion method (default: 'frecent'; 'legacy' for # alphabetic sorting) -# ZSHZ_DATA -> name of datafile (default: ~/.z) +# ZSHZ_DATA -> name of datafile (default: $ZDOTDIR/.z else ~/.z) # ZSHZ_EXCLUDE_DIRS -> array of directories to exclude from your database # (default: empty) # ZSHZ_KEEP_DIRS -> array of directories that should not be removed from the @@ -170,9 +170,12 @@ zshz() { exit fi - # If the user specified a datafile, use that or default to ~/.z + # If the user specified a datafile, use it else default to $ZDOTDIR/.z otherwise default to $HOME/.z # If the datafile is a symlink, it gets dereferenced - local datafile=${${custom_datafile:-$HOME/.z}:A} + local datafile=$custom_datafile + : ${datafile:=$HOME/.z} + [[ -f $datafile ]] || datafile=${ZDOTDIR:-$HOME}/.z + datafile=${datafile:A} # If the datafile is a directory, print a warning and exit if [[ -d $datafile ]]; then