Skip to content

Instantly share code, notes, and snippets.

@starstuck
Created May 7, 2020 16:16
Show Gist options
  • Save starstuck/ab3e9ecb3aa5bd9e1da44b3f58896f79 to your computer and use it in GitHub Desktop.
Save starstuck/ab3e9ecb3aa5bd9e1da44b3f58896f79 to your computer and use it in GitHub Desktop.
Quick cygwin paths conversion without calling cygpath
# 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