Last active
June 14, 2018 21:10
-
-
Save jackfirth/1c672df0e50d00af7162 to your computer and use it in GitHub Desktop.
Shell script to automatically add something to the PATH environment variable in your shell profile, defaulting to current directory and ~/.profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env racket | |
#lang racket/base | |
(require racket/file | |
racket/function | |
racket/cmdline) | |
(define (add-path-to-bash-profile! #:path path-string | |
#:profile profile-path-string) | |
(define update-path-line | |
(format "PATH=$PATH:\"~a\"" path-string)) | |
(add-line-to-end-of-file! profile-path-string | |
update-path-line)) | |
(define (add-line-to-end-of-file! file-path-string line-str) | |
(with-output-to-file | |
#:mode 'text #:exists 'append | |
(expand-user-path file-path-string) | |
(thunk (displayln line-str)))) | |
(define (parse-command-line-args!) | |
(command-line #:program "addpath" | |
#:args ([path (current-directory)] | |
[profile "~/.profile"]) | |
(add-path-to-bash-profile! #:path path | |
#:profile profile))) | |
(module+ main | |
(parse-command-line-args!)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment