diff options
author | Case Duckworth | 2023-01-03 23:03:03 -0600 |
---|---|---|
committer | Case Duckworth | 2023-01-03 23:03:03 -0600 |
commit | 59a1f58695d09ab29ddf992b2c0711c94a4039ea (patch) | |
tree | 1de8114d3b60d11b9a3b92422d178f17e1841ea0 /lisp/upload-junk.el | |
parent | bleh (diff) | |
download | emacs-59a1f58695d09ab29ddf992b2c0711c94a4039ea.tar.gz emacs-59a1f58695d09ab29ddf992b2c0711c94a4039ea.zip |
Switch to use-package
Diffstat (limited to 'lisp/upload-junk.el')
-rw-r--r-- | lisp/upload-junk.el | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lisp/upload-junk.el b/lisp/upload-junk.el new file mode 100644 index 0000000..5a9da84 --- /dev/null +++ b/lisp/upload-junk.el | |||
@@ -0,0 +1,47 @@ | |||
1 | ;;; upload-junk.el --- Upload junk -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | (require 'tramp) | ||
6 | |||
7 | (defvar upload-junk-ssh-host "hetzner" | ||
8 | "SSH host to upload to.") | ||
9 | |||
10 | (defvar upload-junk-ssh-root "/junk" | ||
11 | "SSH root folder to upload to.") | ||
12 | |||
13 | (defvar upload-junk-web-host "https://junk.acdw.net" | ||
14 | "Web host to link uploads to.") | ||
15 | |||
16 | (defun upload-junk-file-name (&optional file) | ||
17 | "Return the uploaded filename for FILE." | ||
18 | (let ((file (or file "_.txt"))) | ||
19 | (format "tmp_%s_%x%x.%s" | ||
20 | (file-name-nondirectory (file-name-sans-extension file)) | ||
21 | (time-convert (current-time) 'integer) | ||
22 | (random (* 8 8 8 8)) | ||
23 | (or (file-name-extension file) "txt")))) | ||
24 | |||
25 | (defun upload-junk-region (start end) | ||
26 | "Upload region from START to END to my server." | ||
27 | (interactive "r") | ||
28 | (let* ((s (buffer-substring-no-properties start end)) | ||
29 | (f (upload-junk-file-name (buffer-file-name))) | ||
30 | (w (format "%s/%s" upload-junk-web-host f))) | ||
31 | (with-temp-buffer | ||
32 | (insert s) | ||
33 | (write-file (format "/sshx:%s:%s/%s" | ||
34 | upload-junk-ssh-host | ||
35 | upload-junk-ssh-root | ||
36 | f))) | ||
37 | (kill-new w) | ||
38 | w)) | ||
39 | |||
40 | (defun upload-junk-region-or-buffer () | ||
41 | (interactive) | ||
42 | (if (region-active-p) | ||
43 | (upload-junk-region (region-beginning) (region-end)) | ||
44 | (upload-junk-region (point-min) (point-max)))) | ||
45 | |||
46 | (provide 'upload-junk) | ||
47 | ;;; upload-junk.el ends here | ||