-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiswindopen
executable file
·57 lines (50 loc) · 1.11 KB
/
iswindopen
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
#!/usr/bin/env bash
#
# File:
# iswindopen
#
# Description:
# Check if a window is open by name or class.
#
# Usage:
# iswindopen <window_name>
#
# <window_name>: case-sensitive; may contain regex
#
# Options:
# -c check if a window is open by class instead of by name (case-sensitive;
# class can be specified using the full qualified class string [i.e.
# class and classname; e.g. "xterm.XTerm"]; does not allow regex)
#
# Exit codes:
# 0: window is open
# 1: window is not open
# 2: no arguments error
#
if [ "$#" -eq 0 ]; then
exit 2
fi
while getopts :c OPT; do
case "${OPT}" in
c) OPT_CLASS=true;;
esac
done
shift $((OPTIND - 1))
getWindIdsInClass() {
echo "$(wmctrl -lx | awk -v class="${1}" '$3 ~ class {print $1}')"
}
if [ "${OPT_CLASS}" = 'true' ]; then
if [ -n "$(getWindIdsInClass "${1}")" ]; then
isWindOpen=true
fi
else
while IFS= read wind; do
if echo "${wind}" | grep -q "${1}"; then
isWindOpen=true
fi
done < <(wmctrl -l | awk '{$1=$2=$3=""; print $0}' | sed 's/^[ \t]*//')
fi
if [ "${isWindOpen}" = 'true' ]; then
exit 0
fi
exit 1