Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move default config file to ~/.config/auto-selfcontrol #62

Merged
merged 1 commit into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions auto-selfcontrol
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$HOME/.config/auto-selfcontrol/" ]]; then
CONFIG_FILE="$HOME/.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 "$HOME/.config/auto-selfcontrol/" || true
CONFIG_FILE="$HOME/.config/auto-selfcontrol/config.json"
fi

b=$(tput bold)
Expand Down
7 changes: 6 additions & 1 deletion auto-selfcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pwd import getpwnam
from optparse import OptionParser

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

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

if os.path.exists(local_config_file):
return local_config_file

if os.path.exists(global_config_file):
return global_config_file

if os.path.exists(prev_global_config_file):
return prev_global_config_file

exit_with_error(
"There was no config file found, please create a config file.")

Expand Down