zoxide
zoxide copied to clipboard
Posix shells on Windows might not have, nor require, cygpath
busybox.exe sh is the ash shell on Windows. It uses native windows paths -- G:\foo\bar or G:/foo/bar -- so it doesn't need nor provide cygpath.
Is it reasonable for zoxide init to only call cygpath conditionally, if it's found, skipping it otherwise?
# In busybox.exe sh, we already get native windows paths, albeit with forward slashes
$ pwd -P
G:/repro
$ cd 'G:\repro' # <-- It understands backslashes, too
I think this implementation avoids any performance hit by checking for cygpath only once on startup, baking the decision into the __zoxide_pwd implementation:
if \command -v cygpath >/dev/null
then
__zoxide_pwd() {
\command cygpath -w "$(\command pwd -P)"
}
else
__zoxide_pwd() {
\command pwd -P
}
fi
I'm writing a PR for both this and #1147
Here's the check that Python .venvs use to detect when they need to run cygpath:
VIRTUAL_ENV='G:\dev\myproject\.venv'
if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath &> /dev/null) ; then
VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
fi