diff --git a/gists.org b/gists.org index 59f7bdd..aceb292 100644 --- a/gists.org +++ b/gists.org @@ -496,7 +496,7 @@ It turns out it didn't work as well as I hoped, paredit steals the RET binding s (advice-add #'tempel-insert :around #'my/store-region) #+end_src -* dwim-shell-command to encrypt files with age :emacs:age: +* dwim-shell-command to encrypt files with age :emacs:age:dwim_shell_command: #+begin_src elisp :tangle gists/dwim-shell-command-encrypt-with-age.el (defconst my/cygwin-p (string-equal system-type "cygwin")) @@ -527,6 +527,31 @@ It turns out it didn't work as well as I hoped, paredit steals the RET binding s :post-process-template #'my/dwim-shell-command/convert-path-cygwin)) #+end_src +* dwim-shell-command to upload files to 0x0 :emacs:dwim_shell_command: + +#+begin_src elisp :tangle gists/dwim-0x0-upload.el + (defun my/dwim-shell-command/0x0-upload () + "Upload the marked files to 0x0.st" + (interactive) + (let ((url "https://0x0.st")) + (dwim-shell-command-on-marked-files + "0x0 upload" + (format "curl -Ffile=@<> -Fsecret= %s" url) + :utils "curl" + :post-process-template + ;; Insert the single quotes at the appropriate place according to + ;; 0x0.st example online: + ;; curl -F'file=@yourfile.png' -Fsecret= https://0x0.st + ;; + ;; The placement of these single quotes confuse the escaping + ;; mechanisms of dwim-shell-command, as it considers @ as the + ;; opening 'quote' as it appears right in front of <>. + (lambda (template path) + (string-replace "-Ffile" "-F'file" + (string-replace path (concat path "'") template)))))) +#+end_src + + * Apply maybe #+begin_src elisp :tangle gists/apply-maybe.el diff --git a/gists/dwim-0x0-upload.el b/gists/dwim-0x0-upload.el new file mode 100644 index 0000000..a18dfb6 --- /dev/null +++ b/gists/dwim-0x0-upload.el @@ -0,0 +1,19 @@ +(defun my/dwim-shell-command/0x0-upload () + "Upload the marked files to 0x0.st" + (interactive) + (let ((url "https://0x0.st")) + (dwim-shell-command-on-marked-files + "0x0 upload" + (format "curl -Ffile=@<> -Fsecret= %s" url) + :utils "curl" + :post-process-template + ;; Insert the single quotes at the appropriate place according to + ;; 0x0.st example online: + ;; curl -F'file=@yourfile.png' -Fsecret= https://0x0.st + ;; + ;; The placement of these single quotes confuse the escaping + ;; mechanisms of dwim-shell-command, as it considers @ as the + ;; opening 'quote' as it appears right in front of <>. + (lambda (template path) + (string-replace "-Ffile" "-F'file" + (string-replace path (concat path "'") template))))))