summary refs log tree commit diff
path: root/emenu.el
blob: 6293cf0c83d7f7841da197d71a5c208f21bb6b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(require 'cl-seq)
(require 'ido)

(defun all-commands ()
  "does a completing read of all the programs accessible to you in $PATH"
  (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)))

(defun emenu (&optional command-list)
  "A dmenu-inspired application launcher using a separate emacs frame"
  (interactive)
  (with-selected-frame (make-frame '((name . "emenu")
                                     (minibuffer . only)
                                     (width . 151)
                                     (height . 1)))
    (unwind-protect
        (progn
          (call-process
           (ido-completing-read "Command: " (or
                                             command-list
                                             (all-commands)))
           nil
           0)
          (keyboard-quit))
      (delete-frame))))