From 4332c344e9c8db4db7a1221a49d0d2a09a0c2335 Mon Sep 17 00:00:00 2001 From: kske Date: Mon, 16 Aug 2021 12:54:28 +0200 Subject: [PATCH] Use XDG config directory In addition, extracted some file paths into variables. --- paperchanger.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/paperchanger.sh b/paperchanger.sh index 85205e6..7a9916b 100755 --- a/paperchanger.sh +++ b/paperchanger.sh @@ -2,21 +2,24 @@ # Simple CLI to make wallpaper changes with xwallpaper more comfortable -mkdir -p $HOME/.paperchanger +CONF_DIR=${XDG_CONFIG_HOME:-~/.config}/paperchanger +CONF_CURRENT_WP=${CONF_DIR}/current_wallpaper.txt +CONF_PATH=${CONF_DIR}/paperchanger.conf.sh +mkdir -p ${CONF_DIR} -if [[ ! -f "$HOME/.paperchanger/current_wallpaper.txt" ]]; then - touch $HOME/.paperchanger/current_wallpaper.txt +if [[ ! -f ${CONF_DIR} ]]; then + touch ${CONF_DIR} fi -if [[ ! -f "$HOME/.paperchanger/paperchanger.conf.sh" ]]; then +if [[ ! -f ${CONF_PATH} ]]; then echo '# This is the configuration file used by the paperchanger program -default_directory=' > $HOME/.paperchanger/paperchanger.conf.sh +default_directory=' > ${CONF_DIR}/paperchanger.conf.sh fi -read -r current_file_path < $HOME/.paperchanger/current_wallpaper.txt -source $HOME/.paperchanger/paperchanger.conf.sh +read -r current_file_path < ${CONF_CURRENT_WP} +source ${CONF_CURRENT_WP} function _help() { echo "" @@ -41,11 +44,11 @@ function _display() { function _set() { current_file_path="$1" - echo "$current_file_path" > $HOME/.paperchanger/current_wallpaper.txt + echo "$current_file_path" > ${CONF_CURRENT_WP} } function _change_config_path() { - sed -i "s/^default_directory=.*\$/default_directory=${1//\//\\/}/" $HOME/.paperchanger/paperchanger.conf.sh + sed -i "s/^default_directory=.*\$/default_directory=${1//\//\\/}/" ${CONF_PATH} } case "$#" in