-
Notifications
You must be signed in to change notification settings - Fork 0
/
closer
executable file
·85 lines (72 loc) · 2.48 KB
/
closer
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
#
# closer
usage() {
base="$(basename "$0")"
cat >&2 << EOF
Usage:
$ $base -u | up < -s | screen > : Focus next window up.
$ $base -l | left < -s | screen > : Focus next window left.
$ $base -d | down < -s | screen > : Focus next window down.
$ $base -r | right < -s | screen > : Focus next window right.
$ $base -h | help < -s | screen > : Show this help.
EOF
[ $# -eq 0 ] || exit "$1"
}
windowUp() {
if [ "$PFW" = "0x00000000" ]; then
mouseY="$(wmp -r)" mouseY="${mouseY#* }"
printf '%s\n' "$wids" | (xargs wattr yi; printf '%s\n' "$mouseY") | \
sort -nr | sed -n "/$mouseY/{n;p}" | cut -d\ -f 2
else
printf '%s\n' "$wids" | xargs wattr yi | sort -nr | \
sed -n "/$PFW/{n;p}" | cut -d\ -f 2
fi
}
windowDown() {
if [ "$PFW" = "0x00000000" ]; then
mouseY="$(wmp -r)" mouseY="${mouseY#* }"
printf '%s\n' "$wids" | (xargs wattr yi; printf '%s\n' "$mouseY") | \
sort -n | sed -n "/$mouseY/{n;p}" | cut -d\ -f 2
else
printf '%s\n' "$wids" | xargs wattr yi | sort -n | \
sed -n "/$PFW/{n;p}" | cut -d\ -f 2
fi
}
windowLeft() {
if [ "$PFW" = "0x00000000" ]; then
mouseX="$(wmp -r)" mouseX="${mouseX% *}"
printf '%s\n' "$wids" | (xargs wattr xi; printf '%s\n' "$mouseX") | \
sort -nr | sed -n "/$mouseX/{n;p}" | cut -d\ -f 2
else
printf '%s\n' "$wids" | xargs wattr xi | sort -nr | \
sed -n "/$PFW/{n;p}" | cut -d\ -f 2
fi
}
windowRight() {
if [ "$PFW" = "0x00000000" ]; then
mouseX="$(wmp -r)" mouseX="${mouseX% *}"
printf '%s\n' "$wids" | (xargs wattr xi; printf '%s\n' "$mouseX") | \
sort -n | sed -n "/$mouseX/{n;p}" | cut -d\ -f 2
else
printf '%s\n' "$wids" | xargs wattr xi | sort -n | \
sed -n "/$PFW/{n;p}" | cut -d\ -f 2
fi
}
main() {
. fwmrc
PFW="$(pfw 2> /dev/null || printf '%s\n' "0x00000000")"
case "$2" in
-s|--screen|screen) wids="$(listwindows)" ;;
*) wids="$(lsw)" ;;
esac
case "$1" in
-u|--up|up) focus --wid "$(windowUp)" ;;
-d|--down|down) focus --wid "$(windowDown)" ;;
-l|--left|left) focus --wid "$(windowLeft)" ;;
-r|--right|right) focus --wid "$(windowRight)" ;;
-h|--help|help) usage 0 ;;
*) usage 1 ;;
esac
}
main "$@"