-
Notifications
You must be signed in to change notification settings - Fork 2
/
.economy-mode.sh
64 lines (56 loc) · 1.38 KB
/
.economy-mode.sh
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
_economy_services=(
"docker"
"ntpd"
"sshd"
"NetworkManager"
)
_economy_programs=(
"geary --hidden"
"nm-applet"
"dropbox"
"telegram-desktop"
"slack"
)
function _programid {
echo $1 | cut -d ' ' -f1
}
function economy-run-services {
for serv in $_economy_services; do
echo "[info] enabling '$serv' server"
sudo rc-service $serv start
done
}
function economy-kill-services {
for serv in $_economy_services; do
echo "[info] disabling '$serv' server"
sudo rc-service $serv stop
done
}
function economy-run-programs {
for program in $_economy_programs; do
local p=$(_programid "${program}")
if ! pgrep -f $p > /dev/null; then
echo "[info] starting '$program' program"
daemonize $p > /dev/null
fi
done
}
function economy-kill-programs {
for program in $_economy_programs; do
local p=$(_programid "${program}")
if pgrep -f $p > /dev/null; then
echo "[info] killing '$program' program"
pgrep -f $p | xargs kill
fi
done
}
function economy-mode-enable {
economy-kill-services && economy-kill-programs
echo "[info] setting to battery mode with tlp"
sudo tlp bat
}
function economy-mode-disable {
economy-run-services && economy-run-programs
echo "[info] setting to AC mode with tlp"
sudo tlp ac
}