elpa

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

emenu-20220222.1156.el (2698B)


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