zoxide icon indicating copy to clipboard operation
zoxide copied to clipboard

Posix shells on Windows might not have, nor require, cygpath

Open cspotcode opened this issue 1 month ago • 2 comments

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

cspotcode avatar Nov 18 '25 15:11 cspotcode

I'm writing a PR for both this and #1147

cspotcode avatar Nov 18 '25 15:11 cspotcode

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

cspotcode avatar Nov 19 '25 16:11 cspotcode