From 02f7d98eb25165ffd7ebe060a8f588082cce263e Mon Sep 17 00:00:00 2001 From: Serge Bibauw Date: Tue, 25 May 2021 22:42:34 -0500 Subject: [PATCH] Changing default location for CONFIG_FILE CONFIG_FILE will be looked for in - ~/.config/auto-selfcontrol/ - /usr/local/etc/auto-selfcontrol/ - $DIR/ (same directory as where Auto-SelfControl has been installed) If not found, created in ~/.config/auto-selfcontrol/config.json This will make it easier to backup and sync it across installs. Answers #58 This will not move an existing config file. Moving can be done manually to ~/.config/auto-selfcontrol/config.json (and removing the previous location) and Auto-selfcontrol will find the new location. --- auto-selfcontrol | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/auto-selfcontrol b/auto-selfcontrol index be76513..15d6e2b 100755 --- a/auto-selfcontrol +++ b/auto-selfcontrol @@ -3,12 +3,17 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -# Check if auto-selfcontrol was installed through brew and set the config.json location accordingly -if [[ $DIR == /usr/local/* ]]; then - mkdir -p /usr/local/etc/auto-selfcontrol || true +# Check if config file already exists +if [[ -d "~/.config/auto-selfcontrol/" ]]; then + CONFIG_FILE="~/.config/auto-selfcontrol/config.json" +elif [ -f "/usr/local/etc/auto-selfcontrol/config.json" ]; then CONFIG_FILE="/usr/local/etc/auto-selfcontrol/config.json" -else +elif [ -f "$DIR/config.json" ]; then CONFIG_FILE="$DIR/config.json" +else + # No config file found: create it in ~/.config/auto-selfcontrol/ + mkdir -p "~/.config/auto-selfcontrol/" || true + CONFIG_FILE="~/.config/auto-selfcontrol/config.json" fi b=$(tput bold)