summaryrefslogtreecommitdiffstats
path: root/herbstluftwm
diff options
context:
space:
mode:
authorGravatar Tom Willemse2015-09-13 23:16:14 +0200
committerGravatar Tom Willemse2015-09-13 23:16:14 +0200
commitb491df4af614d04b08eaae383e187d651dddf798 (patch)
tree74399d03d5c00a81a1f545f080bc9c6a315c2210 /herbstluftwm
parent1a2a7141aee4efca47fd080a4bafa6a46e30552b (diff)
downloaddotfiles-b491df4af614d04b08eaae383e187d651dddf798.tar.gz
dotfiles-b491df4af614d04b08eaae383e187d651dddf798.zip
Update hrunorraise
- Move implementation to scsh - Cycle through possible windows
Diffstat (limited to 'herbstluftwm')
-rwxr-xr-xherbstluftwm/usr/bin/hrunorraise68
1 files changed, 51 insertions, 17 deletions
diff --git a/herbstluftwm/usr/bin/hrunorraise b/herbstluftwm/usr/bin/hrunorraise
index ac449e4..6e91aa6 100755
--- a/herbstluftwm/usr/bin/hrunorraise
+++ b/herbstluftwm/usr/bin/hrunorraise
@@ -1,17 +1,51 @@
-#!/bin/bash
-# hrunorraise --- Raise a window or start a new process
-#
-# Tries to find a window ID for a window with a given class value. If
-# no such window can be found treat the rest of the command line as
-# the command to start.
-#
-# This script depends on both herbstluftwm and wmctrl.
-
-WINID=$(wmctrl -lx | grep "\.$1" | awk '{ print $1 }')
-
-if [ -n "${WINID}" ]; then
- herbstclient jumpto "${WINID}"
-else
- shift
- exec "$@"
-fi
+#!/usr/local/bin/scsh \
+-o srfi-2 -s
+!#
+
+(define client-regexp
+ (rx " " (submatch "0x" (= 7 hex))))
+
+(define current-client
+ (run/string (herbstclient -n attr clients.focus.winid)))
+
+(define (extract-client-id potential-client)
+ (and-let* ((matched (regexp-search client-regexp potential-client)))
+ (match:substring matched 1)))
+
+(define (compact lst)
+ "Filter #f values from LST."
+ (filter (lambda (x) x) lst))
+
+(define clients
+ (compact (map extract-client-id
+ (run/strings (herbstclient attr clients)))))
+
+(define (client-class client-id)
+ (let ((path (string-append "clients." client-id ".class")))
+ (run/string (herbstclient -n attr ,path))))
+
+(define clients-with-class
+ (map (lambda (client)
+ (cons client (client-class client)))
+ clients))
+
+(define classed-clients
+ (map car
+ (filter (lambda (client-and-class)
+ (string= (cdr client-and-class)
+ (car command-line-arguments)))
+ clients-with-class)))
+
+(define (next-client)
+ (and-let* ((tail (member current-client classed-clients)))
+ (cdr tail)))
+
+(define new-client
+ (let ((next (next-client)))
+ (if (or (not next) (null? next))
+ (car (or (and (not (null? classed-clients)) classed-clients) '(#f)))
+ (car next))))
+
+(if new-client
+ (run (herbstclient jumpto ,new-client))
+ (exec-epf (,@(cdr command-line-arguments))))