mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.35k stars 348 forks source link

Allow case-insensitive filename globbing; add nocaseglob #1073

Closed theclapp closed 7 months ago

theclapp commented 7 months ago

Rationale: I use expand.Fields to do filename expansion, for which I'd like to do case-insensitive matching. E.g. I'd like "c*" to match both "cmd" and "CHANGELOG.md"

mvdan commented 7 months ago

Rationale: I use expand.Fields to do filename expansion, for which I'd like to do case-insensitive matching. E.g. I'd like "c*" to match both "cmd" and "CHANGELOG.md"

Can you give some context in terms of when is this useful for a shell? I see nocaseglob in man bash, which alone is probably enough to need this Go API, but I wonder if your need comes from elsewhere.

theclapp commented 7 months ago

I have an terminal/shell app that uses this package as its shell interpreter. It also, as mentioned in this PR, uses expand.Fields to do filename expansion, like bash does when you press tab. So I'd like c to expand to both "cmd" and "CHANGELOG.md". My app translates "c" to "c*" and calls expand.Fields.

This is similar to if you set shopt -s nocaseglob in bash and type "c*".

Would you like me to add the "nocaseglob" shopt and make it set this flag?

mvdan commented 7 months ago

OK gotcha, makes sense. If you want to wire it up to the interpreter that would be nice as a way to make this change a bit more well rounded and get the easy win, but it's not a must. I'll review later.

theclapp commented 7 months ago

I added the nocaseglob shopt, force-pushed, and updated the title and description of the PR.