A couple of handy Emacs functions
24 Jun 2013First, a short function to attach a file when editing a Markdown page in ikiwiki:
(defun x-hugh-wiki-attach-file-to-wiki-page (filename)
"This is my way of doing things."
(interactive "fAttach file: ")
;; doubled slash, but this makes it clear
(let* ((page-name (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))
(local-attachments-dir (format "%s/attachments/%s" (file-name-directory (buffer-file-name)) page-name))
(attachment-file (file-name-nondirectory filename))
(attachment-url (format "https://wiki.example.org/wiki/attachments/%s/%s" page-name attachment-file)))
(make-directory local-attachments-dir 1)
(copy-file filename local-attachments-dir 1)
(insert-string (format "[[%s|%s]]" attachment-file attachment-url))))
Note the way I'm organizing things: there's a directory in the wiki/tree called "attachments"; a subdirectory is created for each page; and the file is dumped there.
Second, a stupid copy-file-template function for Cfengine:
(defun x-hugh-cf3-insert-file-template (file)
"Insert a copy-file template."
(interactive "sFile to copy: ")
(newline-and-indent)
(insert-string (format "\"%s\"" file))
(newline-and-indent)
(insert-string (format " comment => \"Copy %s into place.\"," file))
(newline-and-indent)
(insert-string (format " perms => mog(\"0755\", \"root\", \"wheel\"),"))
(newline-and-indent)
(insert-string (format " copy_from => secure_cp(\"$(g.masterfiles)/centos/5%s\", \"$(g.masterserver)\";" file)))
Both are mostly learning exercises and excuses to post.
Add a comment:
Name and email required; email is not displayed.
Related Posts
QRP weekend 08 Oct 2018
Open Source Cubesat Workshop 2018 03 Oct 2018
mpd crash? try removing files in /var/lib/mpd/ 11 Aug 2018