blob: 169d34ec877b41e3192c1b835b63a7321d938835 (
plain) (
blame)
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
|
#!/usr/bin/env bb
(require '[clojure.java.shell :refer [sh]])
(require '[babashka.process :as process])
(defn tmux-open-term [name cmd args]
(-> (apply sh "tmux" "new-window" "-n" name
"-e" (str "KAKOUNE_SESSION=" (System/getenv "KAKOUNE_SESSION"))
"-e" (str "KAKOUNE_CLIENT=" (System/getenv "KAKOUNE_CLIENT"))
cmd args)
:exit (= 0)))
(defn tmux-focus-term [name]
(-> (sh "tmux" "select-window" "-t" name)
:exit (= 0)))
(defn x11-class [name] (str "kak-term-" name))
(defn x11-open-term [name cmd args]
(apply process/shell "setsid" "-f" "st" "-c" (x11-class name) "-t" name "-e" cmd args))
(defn x11-focus-term [name]
(-> (sh "xdotool" "search" "--class" (x11-class name) "windowactivate")
:exit (= 0)))
(defn cmd-terminal-singleton [[name cmd & args]]
(if (empty? (System/getenv "TMUX"))
(or (x11-focus-term name) (x11-open-term name cmd args))
(or (tmux-focus-term name) (tmux-open-term name cmd args))))
(def commands
{"singleton" cmd-terminal-singleton})
(let [[cmd & args] *command-line-args*]
(if-let [command-fn (commands cmd)]
(command-fn args)
(binding [*out* *err*]
(println (str "invalid command: " (or cmd "")))
(println (str "Valid commands: " (keys commands))))))
|