Skip to content

Instantly share code, notes, and snippets.

@Gavinok
Last active December 18, 2022 22:19
Show Gist options
  • Save Gavinok/7dfa5569c1b706095b05c4a0aa934085 to your computer and use it in GitHub Desktop.
Save Gavinok/7dfa5569c1b706095b05c4a0aa934085 to your computer and use it in GitHub Desktop.
Create a gist from a given region interactively. Depends on the `gh` command line interface
(defun gist-from-region (BEG END fname desc &optional private)
"Collect the current region creating a github gist with the
filename FNAME and description DESC.
If the opitonal argument PRIVATE is non-nil then the gist will be
made private. Otherwise the gist will be default to public"
(interactive (list (mark) (point)
(read-string "File Name: ")
(read-string "Description: ")
current-prefix-arg))
(let ((fname-arg (concat "--filename " fname))
(desc-arg (concat "--desc " (shell-quote-argument desc)))
(private-arg (if private
"--public"
"")))
(shell-command-on-region BEG END (format "gh gist create %s %s %s -"
fname-arg
desc-arg
private-arg))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment