Created
May 7, 2020 16:16
-
-
Save starstuck/ab3e9ecb3aa5bd9e1da44b3f58896f79 to your computer and use it in GitHub Desktop.
Quick cygwin paths conversion without calling cygpath
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
# Following path conversion functions assume that cygrdives are mounted at root. | |
# Your fstab entry should look like this: | |
# | |
# none / cygdrive binary,posix=0,noacl,user 0 0 | |
# | |
declare -A _CYGDRIVEMAP=([C]="/c" [P]="/p") | |
# Convert mixed path to unix path. Mixed path is using windows drive at the beginning, | |
# but with forward slashes already | |
to_unix_path () { | |
local _DRIVE | |
if [ "${1#[A-Z]:/}" != "$1" ]; then | |
_DRIVE="${1:0:1}" | |
echo "${_CYGDRIVEMAP[$_DRIVE]}${1:2}" | |
return | |
fi | |
echo $1 | |
} | |
# Example call | |
echo $(to_unix_path "C:/Users/starstuck") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment