commit 340906a
hovercats
·
2024-09-06 02:13:28 +0000 UTC
parent 7797d63
focus: rewrite in rc
A
rc/focus
+27,
-0
1@@ -0,0 +1,27 @@
2+#!/bin/rc
3+
4+flag e +
5+
6+fn usage {
7+ printf 'Usage: next|prev|top|wid\n'
8+ exit 1
9+}
10+
11+switch($1) {
12+case next
13+ wid=`{lsw | grep -v `{pfw} | sed '1 p;d'}
14+case prev
15+ wid=`{lsw | grep -v `{pfw} | sed '$ p;d'}
16+case top
17+ wid=`{lsw | sed '$ p;d'}
18+case 0x*
19+ wattr $1 && wid=$1
20+case *
21+ usage
22+}
23+
24+# exit if we can't find another window to focus
25+if (~ $#wid 0) printf 'No window to focus on\n' && exit 1
26+
27+chwso -r $wid # put it on top of the stack
28+wtf $wid # set focus on it
D
sh/focus
+0,
-25
1@@ -1,25 +0,0 @@
2-#!/bin/sh
3-#
4-# z3bra - 2014 (c) wtfpl
5-# window focus wrapper that sets borders and can focus next/previous window
6-
7-set -e
8-
9-usage() {
10- printf "usage: %s $(basename "$0") <next|prev|top|wid>\n"
11- exit 1
12-}
13-
14-case $1 in
15- next) wid="$(lsw | grep -v $(pfw) | sed '1 p;d')" ;;
16- prev) wid="$(lsw | grep -v $(pfw) | sed '$ p;d')" ;;
17- top) wid="$(lsw | sed '$ p;d')" ;;
18- 0x*) wattr "$1" && wid="$1" ;;
19- *) usage ;;
20-esac
21-
22-# exit if we can't find another window to focus
23-[ -z "${wid}" ] && exit 1
24-
25-chwso -r "${wid}" # put it on top of the stack
26-wtf "${wid}" # set focus on it