Skip to content

Instantly share code, notes, and snippets.

@aserranoni
Last active February 22, 2023 01:45
Show Gist options
  • Save aserranoni/cd671a989061f88195c39d7c913ff29c to your computer and use it in GitHub Desktop.
Save aserranoni/cd671a989061f88195c39d7c913ff29c to your computer and use it in GitHub Desktop.
Homemade emacs-lisp functions to search bash history and copy commands to the clipboard
(defun ariel/get-file-lines (filename)
(with-temp-buffer (insert-file-contents filename)
(cl-remove-duplicates (split-string (buffer-string) "\n" t)))
)
(defun ariel/copy-string-to-clipboard (str)
(with-temp-buffer (insert str)
(clipboard-kill-region (point-min) (point-max))))
(defun ariel/get-command-from-bash-history ()
(interactive)
(let* (
(strs (ariel/get-file-lines "~/.bash_history"))
)
(ivy-read "Bash History: " strs :action (lambda (x) (ariel/copy-string-to-clipboard x)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment