-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm-select.sh
33 lines (27 loc) · 977 Bytes
/
wm-select.sh
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
#!/bin/bash
#
# Kind of a replacement (or an addon) to usual Alt+Tab functionality
# inspired by OpenBSD's cwm and shows a popupping up dmenu with list of
# currently open windows allowing you to quickly switch between them by
# typing window title.
#
# Dependencies: bash, dmenu, wmctrl
#
current_vd=$(wmctrl -d | sed 's/\( \)\+/ /g' | cut -d' ' -f1,2 |
grep -F '*' | cut -d' ' -f1)
echo "Current virtual desktop is ${current_vd}"
# TODO allow filtering by virtual desktop
oIFS="${IFS}"
IFS=$'\n'
wmlist=`wmctrl -l | sed 's/\( \)\+/ /g'`
wids=(`echo "${wmlist}" | cut -d' ' -f1`)
titles=(`echo "{$wmlist}" | cut -d' ' -f4-`)
IFS="${oIFS}"
ditem=$(printf "%s\n" "${titles[@]}" | awk '{print NR " " $0}' |
dmenu -i -l 5 -p "Title >" | cut -d' ' -f1)
if [ "${ditem}x" != "x" ]; then
widx=$(expr ${ditem} - 1)
echo "Selected: ${wids[$widx]} ${titles[$widx]}"
wmctrl -ia ${wids[$widx]}
fi
# user may have pressed ESC and nothing should be done