-
Notifications
You must be signed in to change notification settings - Fork 23
/
tpdfc
executable file
·74 lines (64 loc) · 1.73 KB
/
tpdfc
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
#!/usr/bin/env bash
# this is a script for controlling running instances of termpdf
function help(){
echo "$(basename $0) usage:"
echo " $(basename $0) <option> <termpdf command>"
echo " options:"
echo " -n N if there is more than one instance of termpdf"
echo " running, communicate with the Nth instance."
echo " (As ordered by pgrep -f termpdf)"
echo " -p PID communicate with the instance of termpdf with"
echo " the specified PID"
echo " -l list all running instances of termpdf"
echo " -h see this help"
echo
echo " <termpdf command> can be any command available from the"
echo " command mode within termpdf. E.g., 'goto 5' will flip to"
echo " page 5."
}
function list_instances(){
echo "N PID FILE"
pgrep -l -f termpdf | cat -n | awk '{print $1,$2,$5}' | column -t
}
n=1
if [[ "$1" == "-h" || "$1" == "--help" || $# -eq 0 ]]; then
help
exit
fi
if ! pgrep -f termpdf &>/dev/null ; then
echo "No instances of termpdf to control."
exit
fi
if [[ "$1" == "-l" ]]; then
list_instances
exit
fi
if [[ "$1" == '-n' ]]; then
shift
if [[ "$1" =~ ^[0-9]+$ ]]; then
n="$1"
shift
else
help
exit 1
fi
fi
if [[ "$1" == '-p' ]]; then
shift
if [[ "$1" =~ ^[0-9]+$ ]]; then
termpdfPID="$1"
shift
else
help
exit 1
fi
else
termpdfPID=$(pgrep -f termpdf | sed $n'q;d')
if [[ $termpdfPID == "" ]]; then
echo "No instance $n of termpdf to control."
list_instances
fi
fi
signal_file="$HOME/.config/termpdf/sigusr1"
echo "$@" > "$signal_file"
kill -SIGUSR1 $termpdfPID