2019-10-09 13:13:56 +02:00
|
|
|
;;; ivy-helpers.el --- More interfaces to ivy -*- lexical-binding: t -*-
|
2020-09-01 11:17:43 +02:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; URL: https://git.wpcarro.dev/wpcarro/briefcase
|
|
|
|
;; Package-Requires: ((emacs "24.3"))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Hopefully to improve my workflows.
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'alist)
|
|
|
|
(require 'tuple)
|
|
|
|
(require 'string)
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(cl-defun ivy-helpers-kv (prompt kv f)
|
2019-10-09 13:13:56 +02:00
|
|
|
"PROMPT users with the keys in KV and return its corresponding value. Calls F
|
|
|
|
with the key and value from KV."
|
|
|
|
(ivy-read
|
|
|
|
prompt
|
|
|
|
kv
|
|
|
|
:require-match t
|
|
|
|
:action (lambda (entry)
|
|
|
|
(funcall f (car entry) (cdr entry)))))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun ivy-helpers-do-run-external-command (cmd)
|
2020-04-02 19:34:49 +02:00
|
|
|
"Execute the specified CMD and notify the user when it finishes."
|
|
|
|
(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)))))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun ivy-helpers-list-external-commands ()
|
2020-09-01 14:44:18 +02:00
|
|
|
"Create a list of all external commands available on $PATH."
|
2020-04-02 19:34:49 +02:00
|
|
|
(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)))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun ivy-helpers-run-external-command ()
|
2020-09-01 14:44:18 +02:00
|
|
|
"Prompts the user with a list of all installed applications to launch."
|
2020-04-02 19:34:49 +02:00
|
|
|
(interactive)
|
2020-09-01 11:17:43 +02:00
|
|
|
(let ((external-commands-list (ivy-helpers-list-external-commands)))
|
2020-04-02 19:34:49 +02:00
|
|
|
(ivy-read "Command:" external-commands-list
|
|
|
|
:require-match t
|
2020-09-01 11:17:43 +02:00
|
|
|
:action #'ivy-helpers-do-run-external-command)))
|
2020-04-02 19:34:49 +02:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;;; Code:
|
|
|
|
(provide 'ivy-helpers)
|
|
|
|
;;; ivy-helpers.el ends here
|