From 374970a9821f4deb56439784b800350b3a681b24 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 23 Apr 2019 07:20:32 -0400 Subject: [PATCH] Add command to upload current buffer to S3 --- emacs/init.org | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/emacs/init.org b/emacs/init.org index 5fa429a..96821a7 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -2597,6 +2597,25 @@ Syntax highlighting for Dockerfiles: (general-def kubernetes-overview-mode-map "SPC" leader-map)) #+END_SRC +* AWS +** S3 +#+BEGIN_SRC emacs-lisp + (defun save-to-s3-sentinel (proc event) + (cond ((string-match-p "finished" event) + (progn + (message (concat "Uploaded to " last-s3-url)) + (kill-buffer "*aws-s3*"))) + (t (message "Failed to upload to s3, check *aws-s3* buffer for details")))) + + (defun save-to-s3 (bucket public) + (interactive "MS3 bucket URL (e.g. s3://bucket/filename): \nP") + (let* ((tmp-file (make-temp-file "s3-upload")) + (cmd `("aws" "s3" "cp" ,@(if public '("--acl" "public-read")) ,tmp-file ,bucket))) + (setq last-s3-url bucket) + (write-region (point-min) (point-max) tmp-file) + (let ((proc (apply #'start-process "aws-s3" "*aws-s3*" cmd))) + (set-process-sentinel proc #'save-to-s3-sentinel)))) +#+END_SRC * Lola Some functions to make my day job easier.