diff options
Diffstat (limited to 'link.scm')
-rwxr-xr-x | link.scm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/link.scm b/link.scm new file mode 100755 index 0000000..d64bb5e --- /dev/null +++ b/link.scm @@ -0,0 +1,30 @@ +#!/usr/bin/env guile +!# +(use-modules (mkdir-p) + (srfi srfi-19)) + +(define dotfiles + '(.emacs + .xsession + .xsessionrc + .exwm + .gitconfig + .config/dunst/dunstrc)) + +(define dotfiles-directory (string-append (getenv "HOME") "/" "dotfiles")) +(define backup-suffix (date->string (current-date) ".~Y~m~d~H~M~S")) + +(define (symlink-dotfile dotfile) + (let ((oldpath (string-append dotfiles-directory "/" (symbol->string dotfile))) + (newpath (string-append (getenv "HOME") "/" (symbol->string dotfile)))) + (cond + ((string-index-right newpath #\/) + => (lambda (i) (mkdir-p (substring newpath 0 i))))) + (call/cc (lambda (skip) + (when (file-exists? newpath) + (when (string=? oldpath (readlink newpath)) + (skip)) + (rename-file newpath (string-append newpath backup-suffix))) + (symlink oldpath newpath))))) + +(for-each symlink-dotfile dotfiles) |