feat(functions): Add ivy-run-external-command
Adds an ivy-based function akin to Helm's helm-run-external-command, but without all the things I don't need/want.
This commit is contained in:
parent
72a33b9156
commit
456f692b88
2 changed files with 37 additions and 1 deletions
|
@ -134,4 +134,40 @@ Including indent-buffer, which should not be called automatically on save."
|
||||||
(buffer-name)
|
(buffer-name)
|
||||||
require-final-newline))
|
require-final-newline))
|
||||||
|
|
||||||
|
;; Helm includes a command to run external applications, which does
|
||||||
|
;; not seem to exist in ivy. This implementation uses some of the
|
||||||
|
;; logic from Helm to provide similar functionality using ivy.
|
||||||
|
(defun list-external-commands ()
|
||||||
|
"Creates a list of all external commands available on $PATH
|
||||||
|
while filtering NixOS wrappers."
|
||||||
|
(cl-loop
|
||||||
|
for dir in (split-string (getenv "PATH") path-separator)
|
||||||
|
when (and (file-exists-p dir) (file-accessible-directory-p dir))
|
||||||
|
for lsdir = (cl-loop for i in (directory-files dir t)
|
||||||
|
for bn = (file-name-nondirectory i)
|
||||||
|
when (and (not (s-contains? "-wrapped" i))
|
||||||
|
(not (member bn completions))
|
||||||
|
(not (file-directory-p i))
|
||||||
|
(file-executable-p i))
|
||||||
|
collect bn)
|
||||||
|
append lsdir into completions
|
||||||
|
finally return (sort completions 'string-lessp)))
|
||||||
|
|
||||||
|
(defun ivy-run-external-command ()
|
||||||
|
"Prompts the user with a list of all installed applications and
|
||||||
|
lets them select one to launch."
|
||||||
|
|
||||||
|
(interactive)
|
||||||
|
(let ((external-commands-list (list-external-commands)))
|
||||||
|
(ivy-read "Command:" external-commands-list
|
||||||
|
:require-match t
|
||||||
|
:history 'external-commands-history
|
||||||
|
:action (lambda (cmd)
|
||||||
|
(message "Starting %s..." cmd)
|
||||||
|
(set-process-sentinel
|
||||||
|
(start-process-shell-command cmd nil cmd)
|
||||||
|
(lambda (process event)
|
||||||
|
(when (string= event "finished\n")
|
||||||
|
(message "%s process finished." process))))))))
|
||||||
|
|
||||||
(provide 'functions)
|
(provide 'functions)
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
(exwm-workspace-switch-create ,i))))
|
(exwm-workspace-switch-create ,i))))
|
||||||
|
|
||||||
;; Launch applications with completion (dmenu style!)
|
;; Launch applications with completion (dmenu style!)
|
||||||
(exwm-input-set-key (kbd "s-d") #'helm-run-external-command)
|
(exwm-input-set-key (kbd "s-d") #'ivy-run-external-command)
|
||||||
(exwm-input-set-key (kbd "s-p") #'ivy-pass)
|
(exwm-input-set-key (kbd "s-p") #'ivy-pass)
|
||||||
|
|
||||||
;; Toggle between line-mode / char-mode
|
;; Toggle between line-mode / char-mode
|
||||||
|
|
Loading…
Add table
Reference in a new issue