aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2021-02-23 15:26:52 +0900
committerMasaya Tojo <masaya@laptop.tojo.local>2021-02-23 20:11:18 +0900
commit3e3687045402c8937682c1ad57f89108f420e50f (patch)
tree3c3675a089b67c48df59bcad5414b77b062c61a6
parent4e7e169b500c694ead1a2b2a99a2c46d13f9923f (diff)
Add `link.scm` script
-rwxr-xr-xlink.scm30
-rw-r--r--manifest.scm1
2 files changed, 31 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)
diff --git a/manifest.scm b/manifest.scm
index 1017f6a..f516cb8 100644
--- a/manifest.scm
+++ b/manifest.scm
@@ -7,6 +7,7 @@
"font-google-noto"
"gnome-icon-theme"
"guile"
+ "guile-mkdir-p"
"emacs"
"emacs-ido-completing-read+"
"emacs-ddskk"