scp
scpaste-http-destinationscpaste-scp-destination
scpaste-http-destination
scpaste-http-destination
scpaste-scp-destination
(require 'url)
(require 'htmlfontify)
(defvar scpaste-http-destination
"http://p.hagelb.org"
"Publicly-accessible (via HTTP) location for pasted files.")
(defvar scpaste-scp-destination
"p.hagelb.org:p.hagelb.org"
"SSH-accessible directory corresponding to `scpaste-http-destination'.
You must have write-access to this directory via `scp'.")
(defvar scpaste-footer
(concat "<p style='font-size: 8pt; font-family: monospace;'>Generated by "
user-full-name
" using <a href='http://p.hagelb.org'>scpaste</a> at %s. "
(cadr (current-time-zone)) ". (<a href='%s'>original</a>)</p>")
"HTML message to place at the bottom of each file.")
(defvar scpaste-el-location load-file-name)
autoload(defun scpaste (original-name)
"Paste the current buffer via `scp' to `scpaste-http-destination'."
(interactive "MName (defaults to buffer name): ")
(let* ((b (save-excursion
(htmlfontify-buffer)
(current-buffer)))
(name (url-hexify-string (if (equal "" original-name)
(buffer-name)
original-name)))
(full-url (concat scpaste-http-destination "/" name ".html"))
(scp-destination (concat scpaste-scp-destination "/" name ".html"))
(scp-original-destination (concat scpaste-scp-destination "/" name))
(tmp-file (concat temporary-file-directory "/" name)))
(save-excursion
(switch-to-buffer b)
(goto-char (point-min))
(search-forward "</body>\n</html>")
(insert (format scpaste-footer
(current-time-string)
(substring full-url 0 -5)))
(write-file tmp-file)
(kill-buffer b))
(shell-command (concat "scp " tmp-file " " scp-destination))
(shell-command (concat "scp " (buffer-file-name (current-buffer))
" " scp-original-destination))
(let ((x-select-enable-primary t))
(kill-new full-url))
(message "Pasted to %s (on kill ring)" full-url)))
autoload(defun scpaste-region (name)
"Paste the current region via `scpaste'."
(interactive "MName: ")
(let ((region-contents (buffer-substring (mark) (point))))
(with-temp-buffer
(insert region-contents)
(scpaste name))))
autoload(defun scpaste-index ()
"Generate an index of all existing pastes on server on the splash page."
(interactive)
(let* ((dest-parts (split-string scpaste-scp-destination ":"))
(files (shell-command-to-string (concat "ssh " (car dest-parts)
" ls " (cadr dest-parts))))
(file-list (split-string files "\n")))
(save-excursion
(with-temp-buffer
(insert-file-contents scpaste-el-location)
(goto-char (point-min))
(search-forward ";;; Commentary")
(forward-line -1)
(insert "\n;;; Pasted Files\n\n")
(dolist (file file-list)
(when (and (string-match "\\.html$" file)
(not (string-match "private" file)))
(insert (concat ";; * <" scpaste-http-destination "/" file ">\n"))))
(emacs-lisp-mode) (font-lock-fontify-buffer) (rename-buffer "SCPaste")
(write-file "/tmp/scpaste-index")
(scpaste "index")))))
(provide 'scpaste)