about summary refs log tree commit diff
path: root/users/tazjin/emacs/config/functions.el
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-08-26T23·22+0300
committertazjin <tazjin@tvl.su>2023-08-26T23·30+0000
commitc6224c9ef586cf367c2fa2ad9a5bc50e307ac084 (patch)
tree87d0aca8da93428e30491fe5a09cd73fb024cc6f /users/tazjin/emacs/config/functions.el
parentb5979f26e8f47638520b0954ac2f1b794ca58880 (diff)
feat(tazjin/emacs): implement run-xdg-app using gio-list-apps tool r/6529
Change-Id: I43111dfc7091c416035be563ca7fc17265667b33
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9158
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'users/tazjin/emacs/config/functions.el')
-rw-r--r--users/tazjin/emacs/config/functions.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/users/tazjin/emacs/config/functions.el b/users/tazjin/emacs/config/functions.el
index a5f109f4b5a6..6e2cff7caec9 100644
--- a/users/tazjin/emacs/config/functions.el
+++ b/users/tazjin/emacs/config/functions.el
@@ -332,4 +332,21 @@ names, instead of only their names (which might change)."
                        (get-buffer name))))
     (switch-to-buffer (or selected name) nil 't)))
 
+(defun run-xdg-app ()
+  "Use `//users/tazjin/gio-list-apps' to retrieve a list of
+installed (and visible) XDG apps, and let users launch them."
+  (interactive)
+  (let* ((apps-json (s-lines (s-trim (shell-command-to-string "gio-list-apps"))))
+         (apps (seq-map (lambda (app)
+                          (let ((parsed (json-parse-string app :object-type 'alist)))
+                            (cons (cdr (assoc 'name parsed))
+                                  (cdr (assoc 'commandline parsed)))))
+                        apps-json))
+
+         ;; Display the command that will be run as an annotation
+         (completion-extra-properties
+          '(:annotation-function (lambda (app) (format " [%s]" (cdr (assoc app apps)))))))
+
+    (run-external-command--handler (cdr (assoc (completing-read "App: " apps nil t) apps)))))
+
 (provide 'functions)