forked from andreasgrill/auto-selfcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-selfcontrol
More file actions
executable file
·66 lines (59 loc) · 2.23 KB
/
auto-selfcontrol
File metadata and controls
executable file
·66 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Auto-SelfControl basic command-line interface
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# 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"
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)
n=$(tput sgr0)
HELP_TEXT="Auto-SelfControl
Small utility to schedule start and stop times of SelfControl.
Usage: ${b}$(basename "$0") <config|activate|help>${n}
where:
${b}config${n} Open the schedule configuration file in a text
editor to set up weekly parameters
${b}activate${n} Activate the automatic start/stop of SelfControl
according to schedules defined in configuration
${b}help${n} Show this help message
More instructions at https://github.com/andreasgrill/auto-selfcontrol"
if [[ $1 ]]; then
case "$1" in
# Edit configuration file
config|edit|set|conf*)
# If no "config.json" found
if [[ ! -f $CONFIG_FILE ]]; then
curl -L -s "https://raw.githubusercontent.com/andreasgrill/auto-selfcontrol/master/config.json" -o $CONFIG_FILE
echo "Downloaded sample configuration in $CONFIG_FILE"
fi
echo "Opening $CONFIG_FILE"
# Opening with default editor set as $EDITOR
if [[ $EDITOR ]]; then
$EDITOR $CONFIG_FILE
# Or with default GUI text editor (txt files > Open with...)
else
open -t $CONFIG_FILE
fi
;;
# Install plist config
activate|install)
sudo python3 $DIR/auto-selfcontrol.py --install --dir "$(dirname $CONFIG_FILE)"
exit 0
;;
-h|--help|help|*)
echo "$HELP_TEXT"
exit 0
;;
esac
else
echo "$HELP_TEXT"
exit 0
fi