-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathi3-on_open
executable file
·60 lines (46 loc) · 1.08 KB
/
i3-on_open
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
#!/bin/sh
tmpf=$(mktemp)
_exit() {
rm "$tmpf"
exit $1
}
# Options
PRINT=false
prosess() {
echo "$dat" > $tmpf
[ "$(< $tmpf jq .change)" == "\"new\"" ] || return
instance="$(< $tmpf jq .container.window_properties.instance)"
([ -z "$NAME" ] || [ "$instance" == "\"$NAME\"" ]) \
|| return
$PRINT && {
< $tmpf jq
_exit 0
}
con_id=$(< $tmpf jq .container.id)
CMDS=()
for arg in "${POSITIONAL[@]}"; do
case $arg in
_*) $(<<< $arg sed 's/^_//') ;;
*) CMDS+=("[con_id=$con_id] $arg;") ;;
esac;
done
i3-msg "${CMDS[@]}"
_exit 0
}
main() {
i3-msg -t subscribe -m '[ "window" ]' \
| while read dat; do prosess "$dat"; done
# | jq -c 'select(.change == "new")' \
}
# Read arguments
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case $1 in
--name) NAME="$2"; shift ;;
--prt) PRINT=true ;;
-h|-?|--help) _usage; exit 0 ;;
-*) echo "Invalid option '$1'" > /dev/stderr; exit 1 ;;
*) POSITIONAL+=("$1") ;;
esac; shift;
done
main "${POSITIONAL[@]}"