-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc_aliases.sh
80 lines (65 loc) · 1.76 KB
/
zshrc_aliases.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
############
# Keylogging
############
print_klog_dest() { echo "written to /var/log/keystroke.log"; }
sneaky_keylogger() {
trap 'print_klog_dest' SIGINT
echo 'KLOG running, dont forget to kill'
sudo keylogger > /dev/null
trap - SIGINT
}
alias klog=sneaky_keylogger
#####################
# Pausing steam games
#####################
pause_pid() {
echo "About to pause $1"
kill -STOP $1
}
# pass the PID as the arg
resume_pid() {
echo "About to resume $1"
kill -CONT $1
}
# echos the PIDs as a string (bash / zsh functions can't return arrays)
echo_steam_pids() {
echo `ps aux | grep -i Steam | grep -v grep | grep -v ipcserver | awk '{print $2}'`
}
pause_steam() {
# zsh doesn't do word splitting like bash
# see https://stackoverflow.com/questions/23157613/how-to-iterate-through-string-one-word-at-a-time-in-zsh
echo "Pausing steam"
local pids=$(echo_steam_pids)
local pid
for pid in ${(z)pids}; do
pause_pid $pid
done
}
resume_steam() {
echo "Resume steam"
local pids=$(echo_steam_pids)
local pid
for pid in ${(z)pids}; do
resume_pid $pid
done
}
echo_divinity_pid() {
echo `ps aux | grep Divinity | grep -v grep | awk '{print $2}'`
}
test_divinity_running() {
if [ -z `echo_divinity_pid` ]; then
echo "Divinity isn't running, quiting"
return 1
else
echo "Divinity running, presumably about to pause / resume"
fi
}
pause_divinity() {
test_divinity_running && pause_pid `echo_divinity_pid` && pause_steam
}
resume_divinity() {
test_divinity_running && resume_pid `echo_divinity_pid` && resume_steam
}
# these aliases need to wrap a function so that we don't hard-code the divinity pid
alias pdiv=pause_divinity
alias rdiv=resume_divinity