;;; emenu.el --- An emacs dmenu clone -*- lexical-binding: t; -*- ;; Copyright © 2023 Erik Oosting ;; Author: Erik Oosting ;; Keywords: application-launcher, misc ;; URL: https://crazazy.tilde.cafe/emenu.git/log.html ;;; License: ;; This file comes with the MIT license, and without any warranty whatsoever ;; You can do with this stuff whatever you want to, but just remember ;; to put me in the footnote :D. Would be nice at least ;;; Commentary: ;; This is basically what dmenu does, but then in emacs. There is a function 'all-commands' ;; that gets you all the commands that are on your system. If you instead want to use emenu ;; on a different list of strings, you can just pass that list to emenu itself and it will ;; let you select something yourself ;;; Code: (require 'cl-seq) (require 'ido) ;;;###autoload (defun emenu--all-commands () "returns a list of all the programs accessible to you in $PATH" ;; This ls-output part was mostly created by phundrak because he found my shell-piping implementation ;; inelegant. If something has to change about this chances are this is going to return to shell ;; scripting again (let ((ls-output (mapcan (lambda (path) (when (file-readable-p path) (cl-remove-if (lambda (file) (let ((fullpath (concat path "/" file))) (or (file-directory-p fullpath) (not (file-executable-p fullpath))))) (directory-files path nil directory-files-no-dot-files-regexp nil)))) (split-string (getenv "PATH") ":" t))) (alias-output (split-string (shell-command-to-string "alias -p | sed -E 's/^alias ([^=]*)=.*$/\\1/'") "\n"))) (append ls-output alias-output))) ;;;###autoload (defun emenu (action &optional command-list) "A dmenu-inspired application launcher using a separate emacs frame" (interactive (list (lambda (command) (call-process command nil 0)))) (with-selected-frame (make-frame '((name . "emenu") (minibuffer . only) (width . 151) (height . 1))) (unwind-protect (progn (funcall action (ido-completing-read "Command: " (or command-list (emenu--all-commands)))) (keyboard-quit)) (delete-frame)))) (provide 'emenu) ;;; emenu.el ends here