Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! env -S csi -s
- ;;
- ;; Remove empty and duplicate entries from a colon-separated path.
- ;;
- ;; For example: ":a:b:b:::c:a::" --> "a:b:c"
- ;;
- (require-extension data-structures)
- (require-extension extras)
- (require-extension srfi-1)
- (let ([args (command-line-arguments)])
- (if (not (= (length args) 1))
- (let ([progname (program-name)])
- (write-string progname #f (current-error-port))
- (write-string ": command line error\n" #f (current-error-port))
- (write-string "Usage: "#f (current-error-port))
- (write-string progname #f (current-error-port))
- (write-string " PATH\n" #f (current-error-port))
- (exit 1))
- (let* ([dirty-path (car args)]
- [dirty-entries (string-split dirty-path ":")]
- [clean-entries (delete-duplicates dirty-entries)]
- [clean-path (string-intersperse clean-entries ":")])
- (write-string clean-path))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement