summaryrefslogtreecommitdiffstats
path: root/.xbindkeysrc.scm
diff options
context:
space:
mode:
Diffstat (limited to '.xbindkeysrc.scm')
-rw-r--r--.xbindkeysrc.scm60
1 files changed, 57 insertions, 3 deletions
diff --git a/.xbindkeysrc.scm b/.xbindkeysrc.scm
index e467941..bf5a77d 100644
--- a/.xbindkeysrc.scm
+++ b/.xbindkeysrc.scm
@@ -1,6 +1,10 @@
;; -*- eval: (git-auto-commit-mode 1) -*-
+(use-modules (ice-9 popen)
+ (ice-9 rdelim))
+
;;; Modkey
(define modkey 'mod4)
+(define dmenu-cmd "dmenu -b -nb '#000000' -nf '#15abc3' -sb '#e0c625' -sf '#000000'")
;;; Macros
(define-macro (cmd command)
@@ -16,6 +20,56 @@
(main-binding)
(grab-all-keys))
+(define (get-tags)
+ (let* ((file (open-input-pipe
+ "TAGS=( $(herbstclient tag_status 0 | tr \":\\!.+#\" \" \") ); echo ${TAGS[@]}"))
+ (tags (string-split (read-line file) #\ )))
+ (close-port file)
+ tags))
+
+(define (get-tag tags pipe)
+ (read-line pipe))
+
+(define (choose-tag prompt tags)
+ (let* ((file (open-input-pipe
+ (string-append "echo '" (string-join tags "\n")
+ "' | " dmenu-cmd " -p '" prompt ":'")))
+ (tag (read-line file)))
+ (close-port file)
+ tag))
+
+(define (switch-tags)
+ "Switch to another tag"
+ (let* ((tags (get-tags))
+ (tag (choose-tag "Switch to tag" tags)))
+ (if (string? tag)
+ (begin
+ (if (not (member tag tags))
+ (run-command (string-append "herbstclient add " tag)))
+ (run-command (string-append "herbstclient use " tag))))
+ (reset-main-binding)))
+
+(define (kill-tag)
+ "Kill a selected tag"
+ (let* ((tags (get-tags))
+ (tag (choose-tag "Kill tag" tags)))
+ (if (string? tag)
+ (begin
+ (if (member tag tags)
+ (run-command (string-append "herbstclient merge_tag " tag)))))
+ (reset-main-binding)))
+
+(define (move-to-tag)
+ "Move selected window to another tag"
+ (let* ((tags (get-tags))
+ (tag (choose-tag "Move to tag" tags)))
+ (if (string? tag)
+ (begin
+ (if (not (member tag tags))
+ (run-command (string-append "herbstclient add " tag)))
+ (run-command (string-append "herbstclient move " tag))))
+ (reset-main-binding)))
+
;;; Maps
(define (main-binding)
"First binding"
@@ -41,10 +95,10 @@
"Second binding"
(ungrab-all-keys)
(remove-all-keys)
- (xbindkey-function '(b) (cmd "~/bin/switch_tags"))
+ (xbindkey-function '(b) switch-tags)
(xbindkey-function `(,modkey c) (cmd "herbstclient quit"))
(xbindkey-function `(,modkey r) (cmd "herbstclient reload"))
- (xbindkey-function '(k) (cmd "~/bin/kill_tag"))
+ (xbindkey-function '(k) kill-tag)
(xbindkey-function '("0") (cmd "herbstclient remove"))
(xbindkey-function '("3") (cmd "herbstclient split horizontal 0.5"))
(xbindkey-function '("2") (cmd "herbstclient split vertical 0.5"))
@@ -53,7 +107,7 @@
(xbindkey-function '(shift f) (cmd "herbstclient fullscreen toggle"))
(xbindkey-function '(p) (cmd "herbstclient pseudotile toggle"))
(xbindkey-function '(r) resize-map)
- (xbindkey-function '(m) (cmd "~/bin/move_to_tag"))
+ (xbindkey-function '(m) move-to-tag)
(xbindkey-function `(,modkey g) reset-main-binding)
(grab-all-keys))