-
Notifications
You must be signed in to change notification settings - Fork 1
/
distraction
53 lines (45 loc) · 1.44 KB
/
distraction
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
#!/bin/sh
DISTRACTION_MAC_APPS=('Twitter.app' 'Flowdock.app')
DISTRACTION_LINUX_APPS=( )
INPLACE="-i"
if [[ $(uname) = 'Darwin' ]]; then
INPLACE="-i ''"
fi
function concentrate_apps() {
# Move all distracting apps to a hidden dotfile prefix
if [[ $(uname) = 'Darwin' ]]; then
for app in ${DISTRACTION_MAC_APPS[@]}; do
if [[ -e "/Applications/$app" ]]; then
sudo mv "/Applications/$app" "/Applications/.distract.$app"
fi
done
fi
}
function distract_apps() {
# Move all hidden distracted apps back to their original location
if [[ $(uname) = 'Darwin' ]]; then
for app in ${DISTRACTION_MAC_APPS[@]}; do
if [[ -e "/Applications/.distract.$app" ]]; then
sudo mv "/Applications/.distract.$app" "/Applications/$app"
fi
done
fi
}
function distract_hosts() {
# Comment out all lines in /etc/hosts ending in #distraction
sudo sed $INPLACE -e 's/\(^[^#].*\)#distraction$/#\1#distraction/' /etc/hosts
}
function concentrate_hosts() {
# Uncomment all lines in /etc/hosts ending in #distraction
sudo sed $INPLACE -e 's/^#\(.*\)#distraction$/\1#distraction/' /etc/hosts
}
function concentrate() {
concentrate_hosts
concentrate_apps
[[ $(uname) = 'Darwin' ]] && sudo dscacheutil -flushcache
}
function distract() {
distract_hosts
distract_apps
[[ $(uname) = 'Darwin' ]] && sudo dscacheutil -flushcache
}