aboutsummaryrefslogtreecommitdiffstats
path: root/herbstluftwm/usr/bin/hlwm-run-or-raise
diff options
context:
space:
mode:
authorGravatar Tom Willemse2016-07-25 22:33:33 +0200
committerGravatar Tom Willemse2016-07-25 22:33:33 +0200
commitf97c9d117c873809600e5f3cf0f4df950ca1613c (patch)
treea05a9b95b82285ffa7964d7cb70594c220ab1e1b /herbstluftwm/usr/bin/hlwm-run-or-raise
parentf43b572693a5d5db1462bc1eec46db8eadea8187 (diff)
downloadnew-dotfiles-f97c9d117c873809600e5f3cf0f4df950ca1613c.tar.gz
new-dotfiles-f97c9d117c873809600e5f3cf0f4df950ca1613c.zip
Add run-or-raise function for herbstluftwm
Diffstat (limited to 'herbstluftwm/usr/bin/hlwm-run-or-raise')
-rwxr-xr-xherbstluftwm/usr/bin/hlwm-run-or-raise43
1 files changed, 43 insertions, 0 deletions
diff --git a/herbstluftwm/usr/bin/hlwm-run-or-raise b/herbstluftwm/usr/bin/hlwm-run-or-raise
new file mode 100755
index 0000000..a06da24
--- /dev/null
+++ b/herbstluftwm/usr/bin/hlwm-run-or-raise
@@ -0,0 +1,43 @@
+#!/usr/local/bin/scsh -s
+!#
+;; 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.
+
+(define (get-current-window-id)
+ (let* ((output (run/string (wmctrl -v -a ":ACTIVE:") (= 2 1)))
+ (re (rx "Using window: "
+ (submatch "0x" (+ hex-digit))
+ "\n"))
+ (match (regexp-search re output)))
+ (match:substring match 1)))
+
+(define (pull-element-to-front elt collection)
+ (if (string= (car collection) elt)
+ collection
+ (pull-element-to-front elt (rotate collection))))
+
+(define (rotate lst)
+ (append (cdr lst) (list (car lst))))
+
+(define current-window-id
+ (get-current-window-id))
+
+(define window-ids
+ (run/strings
+ (pipe (wmctrl -lx)
+ (awk "{ print $1, $3 }")
+ (grep ,(string-append "\\." (car command-line-arguments)))
+ (awk "{ print $1 }"))))
+
+(if (not (null? window-ids))
+ (let ((next-window
+ (if (member current-window-id window-ids)
+ (cadr (pull-element-to-front current-window-id window-ids))
+ (car window-ids))))
+ (run (herbstclient jumpto ,next-window)))
+ (exec-epf (,@(cdr command-line-arguments))))