Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env gosh
- (use file.util)
- (use srfi-1)
- (define (make-ext-matcher extensions)
- (let1 exts (map string->symbol extensions)
- (lambda (path)
- (let1 ext (string->symbol (or (path-extension path) ""))
- (find (lambda (e) (eq? e ext)) exts)))))
- (define (build-tree path ext-matcher)
- (filter-map (lambda (p)
- (cond ((file-is-directory? p) (build-tree p ext-matcher))
- ((ext-matcher p) (list p (file-mtime p)))
- (else #f)))
- (directory-list path :children? #t :add-path? #t)))
- (define (watch path exts command)
- (let* ((matcher (make-ext-matcher (string-split exts #\,)))
- (tree (build-tree path matcher)))
- (let loop ((cur tree) (pre tree))
- (unless (equal? cur pre)
- (sys-system command))
- (sys-sleep 1)
- (loop (build-tree path matcher) cur))))
- (define (usage progname)
- (format (current-error-port) "usage: ~s path-to-watch extentions command\n" progname)
- (sys-exit 1))
- (define (main args)
- (unless (= (length args) 4)
- (usage (car args)))
- (apply watch (cdr args)))
Add Comment
Please, Sign In to add comment