2022-03-03 10:17:04 +01:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# # -*- mode: scheme; -*-
|
|
|
|
IFS=" "
|
|
|
|
exec scsh -s "$0" "$@"
|
2016-07-25 22:33:33 +02:00
|
|
|
!#
|
2016-09-27 02:43:33 +02:00
|
|
|
;; hlwm-run-or-raise --- Raise a window or start a new process
|
2016-07-25 22:33:33 +02:00
|
|
|
;;
|
|
|
|
;; 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)))
|
2016-08-29 15:28:13 +02:00
|
|
|
(and match (match:substring match 1))))
|
2016-07-25 22:33:33 +02:00
|
|
|
|
|
|
|
(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))))
|
2016-11-09 15:01:08 +01:00
|
|
|
(run (hlwm-switch-to-window ,next-window)))
|
2016-07-25 22:33:33 +02:00
|
|
|
(exec-epf (,@(cdr command-line-arguments))))
|