Skip to content

Instantly share code, notes, and snippets.

@rplevy
Last active February 23, 2018 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rplevy/a14282a51cbc02e454a5897241b9a07c to your computer and use it in GitHub Desktop.
Save rplevy/a14282a51cbc02e454a5897241b9a07c to your computer and use it in GitHub Desktop.
defshell, defshellonreg, defregexp
(defmacro defshell (name cmd)
`(defun ,name ()
(interactive)
(insert (shell-command-to-string ,cmd))))
(defmacro defshellonreg (name cmd &optional replace)
`(defun ,name (beg end)
(interactive "r")
(shell-command-on-region beg end ,cmd
(if ,replace (current-buffer) nil)
,replace)))
(defmacro defregexp (name a b)
`(defun ,name ()
(interactive)
(replace-regexp ,a ,b
nil
(if (use-region-p) (region-beginning))
(if (use-region-p) (region-end))
nil)))
(defshellonreg pbcopy-region "pbcopy")
(defshellonreg xml->clj-region "xmlclj" t)
(defshellonreg htm2clj-region "html2clj" t)
(defshellonreg edn->json "edn2json" t)
(defshell uuid "uuidgen | awk '{print tolower($0)}' | tr -d '\n'")
(defshell ls "ls")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment