sharkdp/bat

[solved] zsh cygwin - "The file cannot be accessed by the system (os error 1920)", works fine with bash cygwin

sarnobat opened this issue · 2 comments

I love this tool and don't want to be without it even after I die <3

If I start a zsh shell inside a cygwin terminal, I get

$ bat ~/.mydotfile
[bat error]: '~/.mydotfile' The file cannot be accessed by the system (os error 1920)

If I switch to bash, this tool works great (so I know the file exists). It also works on zsh if I use bat cygpath -w ~/.mydotfile (sorry I can't get backticks to show up correctly around cygpath -w ~/mydotfile).

So obviously Cygwin's zsh isn't as bulletproof as bash for these interoperability issues. How tough is it for batcat to do the work? I'm all for clean code so can understand if the answer is no. I'm just wanting to know if this can be fixed since I feel so handicapped without my Unix-like environment with these beautiful colors when I'm forced to work on Windows.

Perhaps bash is expanding the path before passing command-line arguments and zsh isn't? It should be possible to adapt the cygwin wrapper function in the README to work with zsh, which will make it behave like your cygpath example.

That should help get you up and running again with a *nix-like usage within cygwin :)


As for adding native support for cygwin paths inside bat's Windows build, I'm not sure how feasible that would be. The only way bat would be able to tell that it's not being run from a Windows shell that I'm aware of is by reading environment variables, and I'm not sure it's a good idea to change the file opening code based on that alone.

There's also the possibility that the cygwin home is not the same as the Windows user profile directory, which further complicates it. If there's a %USERPROFILE%\.ssh\config and a C:\cygwin\home\user\.ssh\config, which one should it pick? We would have to be confident about bat being run from a cygwin environment when prioritizing the cygwin home, or else it would lead to regressions for Windows users.

On top of that, there's no guarantee that cygwin is located at C:\cygwin. It could be installed anywhere on the hard drive and even on an external drive from what I remember.

I could dive more into exploring the idea if the other maintainers feel like it's something to pursue, but I think it would be better if cygwin had a native bat package that worked within the environment.

Thank you for the quick detailed reply.

I thought choco's version worked but apparently I spoke to soon. It seems that it works inzsh if the file is not a symlink and is local (so no contentious directory paths). I'll take a look at that cygwin wrapper function, and apologies for not finding it before creating the ticket.

EDIT: I think this wrapper function works nicely in zsh 😃

Regardless, I'm marking this as closed.