aboutsummaryrefslogtreecommitdiff
path: root/link.scm
blob: ee795263de0292956046c89741f023f274907f4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env guile
!#
(use-modules (mkdir-p)
             (srfi srfi-19))

(define dotfiles
  '(.emacs
    .exwm
    .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)