Created
December 18, 2022 23:27
-
-
Save Gavinok/964f62f08efa9439f34641b38146ba74 to your computer and use it in GitHub Desktop.
Create a gist from a given region interactively. Depends on the `gh` command line interface. Now Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 ((proc (make-process :name "Gist Creation" | |
:buffer "*Gist URL*" | |
:command (cl-remove :skip | |
(list "gh" | |
"gist" | |
"create" | |
"--filename" fname | |
"--desc" desc | |
(if private | |
:skip | |
"--public") | |
"-")))) | |
(sentenel (lambda (process event) | |
"Listens for process finish and prints the gist's URL" | |
(when (string-match "finis.*" event) | |
(with-current-buffer (process-buffer process) | |
(goto-char (point-max)) | |
(let (line (string-trim (thing-at-point 'line))) | |
(message (format | |
"Gist for file %s created at %s" | |
fname | |
line)))))))) | |
(set-process-sentinel proc sentenel) | |
(process-send-string proc (buffer-substring BEG END)) | |
(process-send-eof proc) | |
(process-send-eof proc))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment