From 5854c3d7f973101e6680f9b41450a5afed64fab7 Mon Sep 17 00:00:00 2001 From: sabadev Date: Sun, 11 Jul 2021 20:49:51 -0400 Subject: [PATCH] Added command line flags --- git-skipper.rkt | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/git-skipper.rkt b/git-skipper.rkt index e6ce564..5ec4e4a 100644 --- a/git-skipper.rkt +++ b/git-skipper.rkt @@ -2,6 +2,7 @@ (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")) @@ -12,9 +13,48 @@ (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))) -- 2.20.1