about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-07-14 21:28:33 -0500
committerCase Duckworth2024-07-14 21:28:33 -0500
commitb57ac15729899892387cf04efed3aca5e2f43ae8 (patch)
tree601639a44c4252db03d52877be74c40d3dcabb32
parentIgnore dots executable (diff)
downloaddots-main.tar.gz
dots-main.zip
Add dots.scm main
-rw-r--r--README31
-rw-r--r--README.md4
-rwxr-xr-xdots.scm139
3 files changed, 143 insertions, 31 deletions
diff --git a/README b/README deleted file mode 100644 index 5c229a7..0000000 --- a/README +++ /dev/null
@@ -1,31 +0,0 @@
1My dotfiles
2there are many like them
3but these ones are mine
4
5----------
6Installing
7----------
8
9- ./dots.sh
10
11see ./dots.sh -h for more details
12
13I don't remember what -d means.
14
15-----------
16What's here
17-----------
18
19- bash / shell stuff
20- emacs
21- x stuff
22- various other repl type stuff
23
24------
25TO ADD
26------
27
28- i3 config
29- msmtp config (must remove PII)
30- keepassxc ?? (can it do the two part config thing?)
31- ... ? \ No newline at end of file
diff --git a/README.md b/README.md new file mode 100644 index 0000000..6917265 --- /dev/null +++ b/README.md
@@ -0,0 +1,4 @@
1# dots by acdw
2
3these are my dotfiles.
4there are many like them but these ones is mine
diff --git a/dots.scm b/dots.scm new file mode 100755 index 0000000..e22e7f8 --- /dev/null +++ b/dots.scm
@@ -0,0 +1,139 @@
1;;; dots/dots.scm --- dots management tool
2;; by Case Duckworth
3
4(import scheme (chicken base)
5 (chicken file)
6 (chicken file posix)
7 (chicken pathname)
8 (chicken process-context)
9 (chicken string))
10
11(define QUIET (make-parameter #f))
12(define NORUN (make-parameter #f))
13(define FORCE (make-parameter #f))
14(define DOTSD
15 (make-parameter
16 (let ((exec-dir (pathname-directory (executable-pathname))))
17 (if (and exec-dir (not (substring-index "csi" exec-dir)))
18 exec-dir
19 (pathname-directory (program-name))))))
20
21(define usage-string
22 (string-append
23 "dots/dots: install dotfiles
24Usage: dots/dots [-h] [-q] [-n] [-f] [-x] [-d] [-D DIR] [FILE...]
25Flags:
26 -h Show this help and exit
27 -q Don't print what's happening
28 -n *Only* print what would happen
29 -f Force links with ln -f
30 -d Link from FILE *to* the dots dir.
31 Default: link from FILE to $HOME.
32Options:
33 -D DIR
34 Define DIR as the dotfile-directory.
35 Default: The script's directory (" (DOTSD) ")
36Parameters:
37 FILE File or directory to link.
38"))
39
40(define (getfiles files)
41 ;; find all of the files in FILES, descending directories
42 (let loop ((files files)
43 (lst '()))
44 (if (null? files) (if (list? lst) lst (list lst))
45 (let ((this (car files)))
46 (if (or (substring-index "README" this) ; Ignore these files
47 (substring-index "dots" this))
48 (loop files lst)
49 ;; Add the current file to the list recursively
50 (loop (cdr files)
51 (if (directory-exists? this)
52 (append (find-files this
53 test: (complement directory?))
54 lst)
55 (cons this lst))))))))
56
57(define (mklink from to)
58 (let ((to-dir (pathname-directory to)))
59 (cond
60 ((not (file-exists? from))
61 (die 3 "Cannot find" from))
62 ((not (file-exists? to))
63 (echo "* ln" from to)
64 #;(file-link from to))
65 ((and (FORCE) (file-exists? to))
66 (echo "* ln -f" from to)
67 #;(file-link from to))
68 (else (echo to "exists: skipping")))))
69
70(define (homify files)
71 (for-each (lambda (f)
72 (mklink f (make-pathname
73 (get-environment-variable "HOME")
74 "" ; is this smart?
75 (string-intersperse
76 (receive (_ _ els) (decompose-directory f) els)
77 "/"))))
78 (getfiles files)))
79
80(define (dotify files)
81 (for-each (lambda (f)
82 (mklink f (make-pathname
83 (DOTSD) (substring f (+ 1 (substring-index "." f))))))
84 (getfiles files)))
85
86(define (main args)
87 (let loop ((action homify)
88 (args args))
89 (if (null? args)
90 (die 1 "Need at least one file argument")
91 (begin
92 (cond
93 ((not (string=? "-" (substring (car args) 0 1))) ; End of flags
94 (action args)
95 (exit 0))
96 ((or (string=? (car args) "-h")
97 (string=? (car args) "-help"))
98 (die 0 usage-string))
99 ((or (string=? (car args) "-q")
100 (string=? (car args) "-quiet"))
101 (QUIET #t))
102 ((or (string=? (car args) "-n")
103 (string=? (car args) "-norun"))
104 (NORUN #t))
105 ((or (string=? (car args) "-f")
106 (string=? (car args) "-force"))
107 (FORCE #t))
108 ((or (string=? (car args) "-d")
109 (string=? (car args) "-dotify"))
110 (set! action dotify))
111 ((or (string=? (car args) "-D")
112 (string=? (car args) "-dotsdir"))
113 (when (null? (cdr args))
114 (die 4 "-D needs an argument"))
115 (DOTSD (cadr args))
116 (loop action (cddr args)))
117 (else (die 2 "Unknown argument: " (car args))))
118 (loop action (cdr args))))))
119
120(define (echo . strs)
121 (unless (QUIET)
122 (parameterize ((current-output-port (current-error-port)))
123 (display (string-intersperse strs " "))
124 (newline))))
125
126(define (die exit-code . message)
127 (cond-expand
128 ((or compiling chicken-script)
129 (parameterize ((current-output-port (current-error-port)))
130 (display (string-intersperse message " "))
131 (newline)
132 (display usage-string)
133 (exit exit-code)))
134 (else (error message))))
135
136(cond-expand
137 ((or compiling chicken-script)
138 (main (command-line-arguments)))
139 (else))