forked from nwg-piotr/tint2-executors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrof
executable file
·67 lines (55 loc) · 2.07 KB
/
rof
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
#!/bin/sh
# This script will launch the command given as an argument if not yet running
# Else it'll give focus to the command window
# Author: Piotr Miller
# e-mail: [email protected]
# Website: http://nwg.pl
# Project: https://github.com/nwg-piotr/tint2-executors
# License: GPL3
# Usage: rof [-P process_name] command
# Dependencies: `xorg-xprop`, `wmctrl`
if [[ $(which xprop) != *"/xprop"* ]]; then
echo -e "\nDependencies: xorg-xprop package missing...\n"
exit
fi
if [[ $(which wmctrl) != *"/wmctrl"* ]]; then
echo -e "\nDependencies: wmctrl package missing...\n"
exit
fi
if [ ! -z "$1" ]; then
if [[ "$1" == "-P" ]]; then
if [ "$#" -ge 3 ]; then
# find process ID
pid=$(xprop -name $2 | grep PID | awk '{print $3}')
if [ ! -z "$pid" ]; then
# find window ID by process ID
win=$(wmctrl -lp | grep $pid | awk '{print $1}')
wmctrl -i -a ${win}
else
sh -c "${@:3} &"
fi
else
echo -e "\nShould be: rof -P process_name command\n"
fi
elif [[ "$1" == *"-h"* ]] || [[ "$1" == *"--help"* ]]; then
echo -e "\nThis script [r]uns a command [o]r sets [f]ocus to its window if command is already running. May be used in two ways:\n"
echo -e "1: \`rof command\` (e.g. \`rof tint2conf\`)\n"
echo -e "- the command and the process name are the same;\n"
echo -e "2: \`rof -P process_name command\` (e.g. \`rof -P zenity zenity-set-volume.sh\`)\n"
echo -e "- where \`zenity-set-volume.sh\` is a script which launches \`zenity\` box with arguments.\n"
else
# find process ID
pid=$(xprop -name $1 | grep PID | awk '{print $3}')
if [ ! -z "$pid" ]; then
# find window ID by process ID
win=$(wmctrl -lp | grep ${pid} | awk '{print $1}')
# "Set focus on window id $win"
wmctrl -i -a ${win}
else
# "Launch a new instance of $1"
sh -c "$@ &"
fi
fi
else
echo -e "\nUsage: rof [-P process_name] command\n"
fi