From 6875cf697b5ddacea228b72faf9609b135177bbf Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Thu, 22 Sep 2016 18:12:45 -0700 Subject: [PATCH] [Emacs] Add a function to edit a script on PATH --- dotfiles/emacs.d/README.org | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 104a0f1d..da8a1452 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -739,6 +739,24 @@ A macro for composing functions together to build an interactive command to copy (defun imalison:concat-symbols (&rest args) (intern (mapconcat 'imalison:maybe-symbol-name args ""))) #+END_SRC +** Edit a script on PATH +#+BEGIN_SRC emacs-lisp +(defun imalison:get-executables-at-path (filepath) + (when (and (file-exists-p filepath) (f-directory? filepath)) + (--filter (let ((fullpath (imalison:join-paths filepath it))) + (and (file-executable-p fullpath) + (not (f-directory? fullpath)))) + (directory-files filepath)))) + +(defun imalison:get-executables-on-path () + (mapcan 'imalison:get-executables-at-path (eshell-parse-colon-path (getenv "PATH")))) + +(defun imalison:edit-script () + (interactive) + (find-file (eshell-search-path + (ido-completing-read "Select a script to edit: " + (imalison:get-executables-on-path))))) +#+END_SRC ** Other #+BEGIN_SRC emacs-lisp (defun imalison:join-paths (&rest paths)