Created
December 13, 2011 05:26
-
-
Save kmcgrath/1470744 to your computer and use it in GitHub Desktop.
Cygwin: $PATH without spaces
This file contains hidden or 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
| # First we need to split $PATH | |
| # on ':' and put each line into | |
| # an array | |
| OLD_IFS=$IFS | |
| IFS=$'\n' | |
| paths=(`echo $PATH | tr -s ":" "\n"`) | |
| IFS=$OLD_IFS | |
| # The paths supplied from Windows | |
| # may not actually exist. These | |
| # paths will cause cygpath to error | |
| # so we will skip them and only | |
| # process actual directories. | |
| valid_paths=(); | |
| for path in "${paths[@]}"; do | |
| if [ -d "${path}" ]; then | |
| # Save the cygdrive we are parsing | |
| cygdrive_save=$(echo $path | grep -oEi "/cygdrive/[a-z]+") | |
| if [[ $cygdrive_save ]]; then | |
| # Get the short version of the path from cygpath | |
| # We can't have ':' in our path so only grab the | |
| # path following C: (or other drive letter) | |
| no_space_path=$(cygpath -a -m -s "${path}" | cut -d : -f 2); | |
| # Use the saved cygdrive from above and | |
| # prepend it to the short path | |
| valid_paths=("${valid_paths[@]}" "${cygdrive_save}${no_space_path}") | |
| else | |
| valid_paths=("${valid_paths[@]}" $path) | |
| fi | |
| fi | |
| done | |
| # Join the valid_paths array with ':' | |
| # and set $PATH | |
| OLD_IFS=$IFS | |
| IFS=":" | |
| PATH="${valid_paths[*]}" | |
| IFS=$OLD_IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment