Skip to content

Commit aff03e8

Browse files
committed
Merge branch 'sbibauw-config-location'
2 parents e6352c2 + e268b22 commit aff03e8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

auto-selfcontrol

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33

44
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
55

6-
# Check if auto-selfcontrol was installed through brew and set the config.json location accordingly
7-
if [[ $DIR == /usr/local/* ]]; then
8-
mkdir -p /usr/local/etc/auto-selfcontrol || true
6+
# Check if config file already exists
7+
if [[ -d "$HOME/.config/auto-selfcontrol/" ]]; then
8+
CONFIG_FILE="$HOME/.config/auto-selfcontrol/config.json"
9+
elif [ -f "/usr/local/etc/auto-selfcontrol/config.json" ]; then
910
CONFIG_FILE="/usr/local/etc/auto-selfcontrol/config.json"
10-
else
11+
elif [ -f "$DIR/config.json" ]; then
1112
CONFIG_FILE="$DIR/config.json"
13+
else
14+
# No config file found: create it in ~/.config/auto-selfcontrol/
15+
mkdir -p "$HOME/.config/auto-selfcontrol/" || true
16+
CONFIG_FILE="$HOME/.config/auto-selfcontrol/config.json"
1217
fi
1318

1419
b=$(tput bold)

auto-selfcontrol.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pwd import getpwnam
1515
from optparse import OptionParser
1616

17-
SETTINGS_DIR = '/usr/local/etc/auto-selfcontrol'
17+
SETTINGS_DIR = os.path.expanduser("~") + '/.config/auto-selfcontrol'
1818

1919
# Configure global logger
2020
LOGGER = logging.getLogger("Auto-SelfControl")
@@ -51,13 +51,18 @@ def find_config():
5151
path=os.path.dirname(os.path.realpath(__file__)))
5252
global_config_file = "{path}/config.json".format(
5353
path=SETTINGS_DIR)
54+
prev_global_config_file = "{path}/config.json".format(
55+
path='/usr/local/etc/auto-selfcontrol')
5456

5557
if os.path.exists(local_config_file):
5658
return local_config_file
5759

5860
if os.path.exists(global_config_file):
5961
return global_config_file
6062

63+
if os.path.exists(prev_global_config_file):
64+
return prev_global_config_file
65+
6166
exit_with_error(
6267
"There was no config file found, please create a config file.")
6368

0 commit comments

Comments
 (0)