From 20fe9174100e1ab995f2fa9316c69a7ddbc74616 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Thu, 4 Nov 2021 11:55:30 +0100 Subject: [PATCH] Support $XDG_CONFIG_HOME Backwards compatible change that supports storing the bookmarks in $XDG_CONFIG_HOME/cd-bookmarks. * If the user as set the previously existing $CD_BOOKMARK_FILE, this is always overriding. * If the user has created the directory/file $XDG_CONFIG_HOME/cd-bookmarks/(bookmarks), use this * Else fall back to old default $HOME/.cdbookmark Fixes #3 --- cd-bookmark | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cd-bookmark b/cd-bookmark index e0dd738..f8a67d4 100644 --- a/cd-bookmark +++ b/cd-bookmark @@ -17,8 +17,18 @@ # or: cd-bookmark [-l] # +function _cdbookmark_get_config_file() { + if ! [ -z ${CD_BOOKMARK_FILE+x} ]; then + echo "$CD_BOOKMARK_FILE" + elif [ -d ${XDG_CONFIG_HOME:-$HOME/.config}/cd-bookmark ]; then + echo "${XDG_CONFIG_HOME:-$HOME/.config}/cd-bookmark/bookmarks" + else + echo "${HOME}/.cdbookmark" + fi +} + typeset -r SCRIPT_NAME="cd-bookmark" -typeset -r BOOKMARK_FILE="${CD_BOOKMARK_FILE:-${HOME}/.cdbookmark}" +typeset -r BOOKMARK_FILE="$(_cdbookmark_get_config_file)" function _cdbookmark_print_usage() { cat << EOF