(require racket/system
racket/port
+ racket/cmdline
racket/string)
(define (git . args) (string-split (with-output-to-string (λ () (system (string-join (cons "git" args))))) "\n"))
(define tail (string-join (list-tail components 1)))
(cons head tail))
+(define (file-string file) (format "\"~a\"" file))
+
(define (ls-files . args) (map split-prefix (git "ls-files" "-v" (string-join args))))
-(define (modified-files) (ls-files "-m"))
-(define (skipped-files) (filter (λ (pair) (equal? "S" (car pair))) (ls-files)))
+(define (modified-files) (map cdr (ls-files "-m")))
+(define (skipped-files) (map cdr (filter (λ (pair) (equal? "S" (car pair))) (ls-files))))
+
+(define (update-index . args) (git "update-index" (string-join args)))
+(define (skip-file file) (update-index "--skip-worktree" (file-string file)))
+(define (no-skip-file file) (update-index "--no-skip-worktree" (file-string file)))
+(define (skip-modified) (for-each skip-file (modified-files)))
+(define (no-skip-all) (for-each no-skip-file (skipped-files)))
+
+#| Programs |#
+(define (program-display-skipped-files)
+ (displayln "Skipped files:")
+ (for-each displayln (skipped-files)))
+
+(define (program-skip-file file)
+ (displayln (format "Skipping file: '~a'" file))
+ (skip-file file)
+ (program-display-skipped-files))
+
+(define (program-no-skip-file file)
+ (displayln (format "Unskipping file: '~a'" file))
+ (no-skip-file file)
+ (program-display-skipped-files))
+
+(define (program-no-skip-all)
+ (displayln "Unskipping every file")
+ (no-skip-all)
+ (program-display-skipped-files))
+
+(define (program-skip-modified)
+ (displayln "Skipping every modified file")
+ (skip-modified)
+ (program-display-skipped-files))
-(skipped-files)
-(modified-files)
+(command-line
+ #:once-any
+ #| (("-i" "--interactive") "Interactive mode" (interactive)) |#
+ (("-l" "--list") "View skipped files" (program-display-skipped-files))
+ (("-s" "--skip") file "Skip single file" (program-skip-file file))
+ (("-n" "--no-skip") file "Unskip single file" (program-no-skip-file file))
+ (("-p" "--no-skip-all") "Unskip every file" (program-no-skip-all))
+ (("-m" "--skip-modified") "Skip every modified file" (program-skip-modified)))