emenu.el (2674B)
1 ;;; emenu.el --- An emacs dmenu clone -*- lexical-binding: t; -*- 2 3 ;; Copyright © 2023 Erik Oosting 4 5 ;; Author: Erik Oosting <crazazy@tilde.cafe> 6 ;; Keywords: application-launcher, misc 7 ;; URL: https://crazazy.tilde.cafe/emenu.git/log.html 8 9 ;;; License: 10 ;; This file comes with the MIT license, and without any warranty whatsoever 11 ;; You can do with this stuff whatever you want to, but just remember 12 ;; to put me in the footnote :D. Would be nice at least 13 14 ;;; Commentary: 15 ;; This is basically what dmenu does, but then in emacs. There is a function 'all-commands' 16 ;; that gets you all the commands that are on your system. If you instead want to use emenu 17 ;; on a different list of strings, you can just pass that list to emenu itself and it will 18 ;; let you select something yourself 19 20 ;;; Code: 21 (require 'cl-seq) 22 (require 'ido) 23 24 ;;;###autoload 25 (defun emenu--all-commands () 26 "returns a list of all the programs accessible to you in $PATH" 27 ;; This ls-output part was mostly created by phundrak because he found my shell-piping implementation 28 ;; inelegant. If something has to change about this chances are this is going to return to shell 29 ;; scripting again 30 (let ((ls-output (mapcan (lambda (path) 31 (when (file-readable-p path) 32 (cl-remove-if (lambda (file) 33 (let ((fullpath (concat path "/" file))) 34 (or (file-directory-p fullpath) 35 (not (file-executable-p fullpath))))) 36 (directory-files path nil directory-files-no-dot-files-regexp nil)))) 37 (split-string (getenv "PATH") ":" t))) 38 (alias-output (split-string (shell-command-to-string "alias -p | sed -E 's/^alias ([^=]*)=.*$/\\1/'") "\n"))) 39 (append ls-output alias-output))) 40 41 ;;;###autoload 42 (defun emenu (action &optional command-list) 43 "A dmenu-inspired application launcher using a separate emacs frame" 44 (interactive (list (lambda (command) (call-process command nil 0)))) 45 (with-selected-frame (make-frame '((name . "emenu") 46 (minibuffer . only) 47 (width . 151) 48 (height . 1))) 49 (unwind-protect 50 (progn 51 (funcall action 52 (ido-completing-read 53 "Command: " (or 54 command-list 55 (emenu--all-commands)))) 56 (keyboard-quit)) 57 (delete-frame)))) 58 59 (provide 'emenu) 60 ;;; emenu.el ends here