summaryrefslogtreecommitdiffstats
path: root/.local/bin/i3-get-window-criteria
diff options
context:
space:
mode:
authorYigit Sever2020-09-16 15:26:42 +0300
committerYigit Sever2020-09-16 15:26:42 +0300
commit3a6003cee585dbdabec939940c4de421dbd122fb (patch)
treecdf5b9b0d6694738e0cde6b32dddbb84f4cf6e7b /.local/bin/i3-get-window-criteria
parent7419b9fc45ba291d5d10a9f5bea3fa5d33dfedc0 (diff)
downloaddotfiles-3a6003cee585dbdabec939940c4de421dbd122fb.tar.gz
dotfiles-3a6003cee585dbdabec939940c4de421dbd122fb.tar.bz2
dotfiles-3a6003cee585dbdabec939940c4de421dbd122fb.zip
move rest of the scripts
Diffstat (limited to '.local/bin/i3-get-window-criteria')
-rwxr-xr-x.local/bin/i3-get-window-criteria40
1 files changed, 40 insertions, 0 deletions
diff --git a/.local/bin/i3-get-window-criteria b/.local/bin/i3-get-window-criteria
new file mode 100755
index 0000000..f46f65e
--- /dev/null
+++ b/.local/bin/i3-get-window-criteria
@@ -0,0 +1,40 @@
1#!/bin/sh
2
3# i3-get-window-criteria - Get criteria for use with i3 config commands
4
5# To use, run this script, then click on a window.
6# Output is in the format: [<name>=<value> <name>=<value> ...]
7
8# Known problem: when WM_NAME is used as fallback for the 'title="<string>"' criterion,
9# quotes in "<string>" are not escaped properly. This is a problem with the output of `xprop`,
10# reported upstream: https://bugs.freedesktop.org/show_bug.cgi?id=66807
11
12PROGNAME=`basename "$0"`
13
14# Check for xwininfo and xprop
15for cmd in xwininfo xprop; do
16 if ! which $cmd > /dev/null 2>&1; then
17 echo "$PROGNAME: $cmd: command not found" >&2
18 exit 1
19 fi
20done
21
22match_int='[0-9][0-9]*'
23match_string='".*"'
24match_qstring='"[^"\\]*(\\.[^"\\]*)*"' # NOTE: Adds 1 backreference
25
26{
27 # Run xwininfo, get window id
28 window_id=`xwininfo -int | sed -nre "s/^xwininfo: Window id: ($match_int) .*$/\1/p"`
29 echo "id=$window_id"
30
31 # Run xprop, transform its output into i3 criteria. Handle fallback to
32 # WM_NAME when _NET_WM_NAME isn't set
33 xprop -id $window_id |
34 sed -nr \
35 -e "s/^WM_CLASS\(STRING\) = ($match_qstring), ($match_qstring)$/instance=\1\nclass=\3/p" \
36 -e "s/^WM_WINDOW_ROLE\(STRING\) = ($match_qstring)$/window_role=\1/p" \
37 -e "/^WM_NAME\(STRING\) = ($match_string)$/{s//title=\1/; h}" \
38 -e "/^_NET_WM_NAME\(UTF8_STRING\) = ($match_qstring)$/{s//title=\1/; h}" \
39 -e '${g; p}'
40} | sort | tr "\n" " " | sed -r 's/^(.*) $/[\1]\n/'