-
Notifications
You must be signed in to change notification settings - Fork 13
/
s3ed.el
96 lines (80 loc) · 3.63 KB
/
s3ed.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; s3ed.el --- Tramp-like access to s3
;; Author: Matt Usifer <[email protected]>
;; Version: 0.2.0
;; Keywords: s3 tools
;; Package-Requires: ((emacs "25.1") (dash "2.17.0") (s "1.12.0"))
;; Homepage: https://github.com/mattusifer/s3ed
;; S3ed is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; S3ed is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; S3ed provides an interface to Amazon S3 from within Emacs. S3ed
;; is inspired by TRAMP, and strives to provide near-seamless access to
;; S3 from standard Emacs functions.
;;; Code:
(require 's3ed-mode)
;; define the two entry points to s3ed - s3ed-find-file and s3ed-save-file
(defun s3ed-find-file ()
"Open s3ed buffer at input-file.
Will be a refreshed dired buffer if it is a directory."
(interactive)
(if s3ed-mode
(let* ((current-s3-base-path (if (s3ed-is-active)
(s3ed-local-path-to-s3-path default-directory)
"s3://"))
(current-s3-file-path (s3ed-completing-read current-s3-base-path
"Find S3 file"))
(current-local-file-path (s3ed-s3-path-to-local-path current-s3-file-path)))
(if (s3ed-is-directory current-s3-file-path)
(progn
(s3ed-refresh-tmp-dir current-local-file-path)
(dired current-local-file-path))
(progn
(s3ed-s3-cp (s3ed-local-path-to-s3-path current-local-file-path)
current-local-file-path)
(find-file current-local-file-path))))
(when (y-or-n-p "S3ed mode is disabled, do you want to enable s3ed? ")
(s3ed-mode)
(s3ed-find-file))))
(defun s3ed-save-file ()
"Save input file to s3."
(interactive)
(if s3ed-mode
(let* ((current-s3-base-path (if (s3ed-is-active)
(s3ed-local-path-to-s3-path default-directory)
"s3://"))
(current-s3-file-path (s3ed-completing-read current-s3-base-path "Save S3 file"))
(current-local-file-path (s3ed-s3-path-to-local-path current-s3-file-path)))
(write-file current-local-file-path)
(s3ed-s3-cp current-local-file-path current-s3-file-path)
(s3ed-refresh-tmp-dir)
(find-file current-local-file-path))
(when (y-or-n-p "S3ed mode is disabled, do you want to enable s3ed? ")
(s3ed-mode)
(s3ed-save-file))))
(defun s3ed-set-profile ()
"Set the configured profile that will be used to access AWS"
(interactive)
(if s3ed-mode
(let* ((target-profile (read-string "S3ed Profile: " s3ed-profile-name)))
(setq s3ed-profile-name target-profile))
(when (y-or-n-p "S3ed mode is disabled, do you want to enable s3ed? ")
(s3ed-mode)
(s3ed-set-profile))))
(defun s3ed-unset-profile ()
"Unset the configured profile that will be used to access AWS"
(interactive)
(if s3ed-mode
(setq s3ed-profile-name nil)
(when (y-or-n-p "S3ed mode is disabled, do you want to enable s3ed? ")
(s3ed-mode)
(s3ed-set-profile))))
(provide 's3ed)
;;; s3ed.el ends here