這兩天想著把org-roam裏的筆記用hugo掛在github page上,但是考慮到管理和隱私等等決定把想要掛上去的筆記同步到網站的文件夾裏.一開始考慮resilio sync之類的同步軟件,但是覺得不太方便,後來想alias,但是傳到github上面alias當然就沒有指向目標了,所以最後還是覺得用rsync比較好.
我在網上找了一段時間,只有找到在dired裏用rsync傳大文件的功能,好像是一個dired enhence的包的一部分.
目標的包大概功能就是:
- 維護一個數據結構,裏面有存src和dest的配置
- 執行一個函數之後可以把所有配置裡的src,dest對都rsync一遍
因為沒有找到所以現在已經自己開始寫.有沒有壇友知道有已經寫好有上述兩個功能的包呢?
應該是?這個repo我沒看到,不過它readme裏提到的三個帖子我都查到過
我寫好了,試了一下能用.不是很長,我就直接貼在這裡啦
;;; package --- Summary
;;; Commentary:
;; This library is to maintain an alist of (src . dest-list) for rsync.
;; the alist is stored in .list-rsync. Each src can have multiple dest-lsit, all of which would be synced after (list-rsync src)
;;; Code:
(defvar list-rsync-alist-file nil
"the location holding the list-rsync-alist")
(defvar list-rsync-alist nil
"the variable holding the alist ((src .dest-list))")
;;test env
(setq list-rsync-alist-file "~/playground/projects/list-rsync/.list-rsync")
;;end test env
; TODO add sync groups
(defun list-rsync-load ()
"load data in `list-rsync-alist-file' into `list-rsync-alist' "
(interactive)
(with-temp-buffer
(insert-file-contents list-rsync-alist-file)
(setq list-rsync-alist (read (current-buffer)))))
(defun list-rsync-save ()
"save `list-rsync-alist' into `list-rsync-alist-file'"
(with-temp-file list-rsync-alist-file
(print list-rsync-alist (current-buffer)))
)
(defun list-rsync-add-link (src dest)
"add dest into dest-list associated with src in `list-rsync-alist'"
(interactive "Fsrc: \nFdest: ")
(message "%s %s" src dest)
(if-let
((entry (assoc src list-rsync-alist)))
(progn
(delete entry list-rsync-alist)
(push (list src (push dest (cdr entry))) list-rsync-alist))
(push (list src (list dest)) list-rsync-alist))
(list-rsync-save)
)
(defun list-rsync-delete-link (src dest)
"delete a dest from (src . dest-list) in `list-rsync-alist'
if dest-list empty, delete the entry"
(interactive "Fsrc: \nFdest: ")
(unless (assoc src list-rsync-alist)
(user-error "no link in list-rsync-alist have %s as source"
src))
(if-let ((entry (cdr (assoc src list-rsync-alist))) )
(progn
(delete entry list-rsync-alist)
(push (list src (delete dest (cdr entry)))
list-rsync-alist))
(delete entry list-rsync-alist)
)
(list-rsync-save)
)
(defun list-rsync-delete-src (src)
(interactive "Fdelete src:")
(delete (assoc src list-rsync-alist) list-rsync-alist)
(list-rsync-save))
(defun list-rsync-sync (src)
"sync src according to `list-rsync-alist'"
(let ((dests (alist-get src
;;"/Users/hermanhe/Notes/RoamNotes/20220430172003-emacs_lisp.org"
list-rsync-alist
nil nil 'equal
)))
(dolist (dest (car dests))
;;use `start-process-shell-command' rather than `async-shell-command' to avoid buffers created for each command.
(start-process-shell-command
"list-rsync"
"*list-rsync*"
(format "rsync -arvz --progress %s %s" src dest)
)
))
)
(defun list-rsync-sync-this-file ()
"sync this file using `list-rsync-sync'"
(interactive)
(save-buffer)
(list-rsync-sync (buffer-file-name))
)
(defun list-rsync-sync-all-file ()
"sync all src on `list-rsync-add-link' to their dests"
(interactive)
(dolist (entry list-rsync-alist)
(list-rsync-sync (car entry))))
(defun list-rsync-sync-these-files (files)
"sync srcs in FILES to their dests"
(dolist (src files)
(list-rsync-sync src)))
(defun list-rsync-sync-link-from-directory (dir)
"sync srcs in `list-rsync-alist' that's in DIR to their dests"
(interactive "Dsync links start from this dir: ")
(dolist (entry list-rsync-alist)
(when (equal dir
(substring
(car entry)
0 (length dir)))
(list-rsync-sync (car entry)))
)
)
(defun list-rsync-sync-link-to-directory (dir)
"sync links in `list-rsync-alist' that end in DIR")
(provide 'list-rsync)
;;; list-rsync.el ends here
下次再給它加一個自定義群組,再加點ivy還是helm裏面經常見到的在list裏面選一個的那個interface,基本上就完全夠用了應該.
update: 還得加上在複製org的時候recursively把用到的image等等也複製過去