Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path separator on windows is not always \ #501

Closed
albfan opened this issue Jun 2, 2017 · 13 comments
Closed

path separator on windows is not always \ #501

albfan opened this issue Jun 2, 2017 · 13 comments
Labels
question An issue that is lacking clarity on one or more points.

Comments

@albfan
Copy link

albfan commented Jun 2, 2017

running under mingw output shows paths with \ but mingw (running bash) uses /

Were is the code related with path separator?, maybe mingw can be detected to fix that

@BurntSushi
Copy link
Owner

There is no automatic detection, but you can use the --path-separator flag to override the path separator in any environment. I imagine sticking it in an alias might work for you?

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label Jun 2, 2017
@albfan
Copy link
Author

albfan commented Jun 2, 2017

On cmd it works, but on mingw bash (the one that git for windows provides if you're curious) it outputs:

$ rg foo --path-separator '/'
A path separator must be exactly one byte, but the given separator is 20 bytes.

@albfan
Copy link
Author

albfan commented Jun 2, 2017

same without quotes

@BurntSushi
Copy link
Owner

That error message is baffling to me. Someone will need to debug it. I'll do it eventually.

@albfan
Copy link
Author

albfan commented Jun 2, 2017

Ok, count on me for that

Seems there's window detecting no?

if b == b'/' || (cfg!(windows) && b == b'\\') {

and docs say it too:
https://github.com/BurntSushi/ripgrep/blob/master/doc/rg.1#L390

Have to check what is behind cfg!(windows)

maybe that can be a better fix. By now options would work

If you want to go for OS detection or want to detect that problem with bytes just open a bug and comment here

@albfan albfan closed this as completed Jun 2, 2017
@BurntSushi
Copy link
Owner

@albfan Why did you close this? If --path-separator isn't working, then that's a bug.

@albfan
Copy link
Author

albfan commented Jun 2, 2017

My problem with choose a separator is resolved:

$ rg foo --path-separator '\x2F'

There's another problem that maybe you want to solve. But feels that is a different issue

Do you want me to reopen this and work that here?

@BurntSushi BurntSushi reopened this Jun 2, 2017
@BurntSushi
Copy link
Owner

@albfan I understand that you found a work-around, but if rg foo --path-separator / is giving your error messages about the path separator being 20 bytes, then that's a bug.

If there's a distinct issue, then I'd say open a new ticket...

@albfan
Copy link
Author

albfan commented Jun 2, 2017

Here some test:

$ rg foo --path-separator /
A path separator must be exactly one byte, but the given separator is 20 bytes.

#this works
$ rg foo --path-separator //

$ rg foo --path-separator aa
A path separator must be exactly one byte, but the given separator is 2 bytes.

$ rg foo --path-separator aaa
A path separator must be exactly one byte, but the given separator is 3 bytes.

$ rg foo --path-separator aaa/
A path separator must be exactly one byte, but the given separator is 4 bytes.

#double do not increase faulty bytes
$ rg foo --path-separator aaa//
A path separator must be exactly one byte, but the given separator is 5 bytes.

$ rg foo --path-separator /a
A path separator must be exactly one byte, but the given separator is 3 bytes.

#what???
$ rg foo--path-separator /aa
A path separator must be exactly one byte, but the given separator is 23 bytes.

$ rg foo--path-separator /aaa
A path separator must be exactly one byte, but the given separator is 24 bytes.

Have to learn how to debug rust, any hint on windows?

@BurntSushi
Copy link
Owner

@albfan Ah, I wonder if the problem here is your shell. Maybe the shell is expanding / to something like /c/cygdrive/ or something similar?

@albfan
Copy link
Author

albfan commented Jun 2, 2017

I think so

@albfan
Copy link
Author

albfan commented Jun 3, 2017

http://www.mingw.org/wiki/Posix_path_conversion

Here we are. / gets translated into a absolute path on mingw. Double // prevents conversion.

That's why 20 bytes

This is solved then

@albfan albfan closed this as completed Jun 3, 2017
@albfan
Copy link
Author

albfan commented Nov 15, 2017

Definitive solution

$ cat ~/.bashrc
...
alias rg='rg --path-separator="//"'
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question An issue that is lacking clarity on one or more points.
Projects
None yet
Development

No branches or pull requests

2 participants