Browse code
chore: refactor git-ignore
Showing 1 changed files
... | ... |
@@ -5,24 +5,39 @@ |
5 | 5 |
|
6 | 6 |
(defpackage :fwoar.git-ignore |
7 | 7 |
(:use :cl)) |
8 |
+(in-package :fwoar.git-ignore) |
|
8 | 9 |
|
9 | 10 |
(defparameter *args* |
10 | 11 |
(uiop:command-line-arguments)) |
11 | 12 |
|
12 |
-(with-open-file (s ".gitignore" :direction :output :if-exists :append :if-does-not-exist :create) |
|
13 |
+(defun trim-spaces (string) |
|
14 |
+ (string-trim '(#\space #\tab #\newline) string)) |
|
15 |
+ |
|
16 |
+(defun get-to-ignore () |
|
17 |
+ (format *query-io* "ignore? ") |
|
18 |
+ (finish-output *query-io*) |
|
19 |
+ (read-line *query-io* nil)) |
|
20 |
+ |
|
21 |
+(defun not-terminator (line) |
|
22 |
+ (and line |
|
23 |
+ (not (string= line "")) |
|
24 |
+ (not (string= line ".")))) |
|
25 |
+ |
|
26 |
+(defmacro loop-until-done ((line) &body body) |
|
27 |
+ `(loop for ,line = (trim-spaces (get-to-ignore)) |
|
28 |
+ while (not-terminator ,line) |
|
29 |
+ do ,@body)) |
|
30 |
+ |
|
31 |
+(with-open-file (s ".gitignore" |
|
32 |
+ :direction :output |
|
33 |
+ :if-exists :append |
|
34 |
+ :if-does-not-exist :create) |
|
13 | 35 |
(fresh-line s) |
14 | 36 |
(if *args* |
15 | 37 |
(format s "~{~a~%~}" *args*) |
16 |
- (loop for line = (string-trim '(#\space #\tab #\newline) |
|
17 |
- (progn (format *query-io* "ignore? ") |
|
18 |
- (finish-output *query-io*) |
|
19 |
- (read-line *query-io* nil))) |
|
20 |
- while (and line |
|
21 |
- (not (string= line "")) |
|
22 |
- (not (string= line "."))) |
|
23 |
- do |
|
24 |
- (princ line s) |
|
25 |
- (terpri s)))) |
|
38 |
+ (loop-until-done (line) |
|
39 |
+ (princ line s) |
|
40 |
+ (terpri s)))) |
|
26 | 41 |
|
27 | 42 |
(uiop:run-program "git add .gitignore" |
28 | 43 |
:force-shell t |