From c6224c9ef586cf367c2fa2ad9a5bc50e307ac084 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 27 Aug 2023 02:22:20 +0300 Subject: feat(tazjin/emacs): implement run-xdg-app using gio-list-apps tool Change-Id: I43111dfc7091c416035be563ca7fc17265667b33 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9158 Tested-by: BuildkiteCI Reviewed-by: tazjin --- users/tazjin/emacs/config/desktop.el | 2 +- users/tazjin/emacs/config/functions.el | 17 +++++++++++++++++ users/tazjin/emacs/default.nix | 3 ++- users/tazjin/gio-list-apps/src/main.rs | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) (limited to 'users/tazjin') diff --git a/users/tazjin/emacs/config/desktop.el b/users/tazjin/emacs/config/desktop.el index 810521db185a..c64073f5f824 100644 --- a/users/tazjin/emacs/config/desktop.el +++ b/users/tazjin/emacs/config/desktop.el @@ -220,7 +220,7 @@ in-progress." (exwm-input-set-key (kbd "C-c j") #'exwm-jump-to-buffer) ;; Launch applications / any command with completion (dmenu style!) -;; (exwm-input-set-key (kbd "s-d") #'counsel-linux-app) ;; TODO(tazjin): completing-read version +(exwm-input-set-key (kbd "s-d") #'run-xdg-app) (exwm-input-set-key (kbd "s-x") #'run-external-command) (exwm-input-set-key (kbd "s-p") #'password-store-lookup) 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) diff --git a/users/tazjin/emacs/default.nix b/users/tazjin/emacs/default.nix index 5b6257478485..09221fd09d45 100644 --- a/users/tazjin/emacs/default.nix +++ b/users/tazjin/emacs/default.nix @@ -1,6 +1,6 @@ # This file builds an Emacs pre-configured with the packages I need # and my personal Emacs configuration. -{ lib, pkgs, ... }: +{ depot, lib, pkgs, ... }: pkgs.makeOverridable ({ emacs ? pkgs.emacs-unstable }: @@ -13,6 +13,7 @@ pkgs.makeOverridable # $PATH for binaries that need to be available to Emacs emacsBinPath = lib.makeBinPath [ + depot.users.tazjin.gio-list-apps (currentTelega pkgs.emacsPackages) pkgs.libwebp # for dwebp, required by telega ]; diff --git a/users/tazjin/gio-list-apps/src/main.rs b/users/tazjin/gio-list-apps/src/main.rs index 2b04ac06a754..c6b6b98d4d9c 100644 --- a/users/tazjin/gio-list-apps/src/main.rs +++ b/users/tazjin/gio-list-apps/src/main.rs @@ -10,6 +10,7 @@ fn main() { "{}", json!({ "name": app.name().as_str(), + "display_name": app.display_name().as_str(), "commandline": cmd, }) ); -- cgit 1.4.1