elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.53k stars 297 forks source link

treat '#' as a bareword if it's after non-whitespace character #1713

Open aca opened 11 months ago

aca commented 11 months ago

Nix takes strings with '#' as an argument

# sudo nixos-rebuild switch --flake .#root --impure # not work
sudo nixos-rebuild switch --flake '.#root' --impure

Can we allow '#' as a bareword if it's after non-whitespace character?

I haven't seen this pattern other than nix, but hope not it requires big changes in the specification.

λ bash -c 'echo 3#4'
3#4
λ fish -c 'echo 3#4'
3#4
krader1961 commented 11 months ago

I think this proposal is a bad idea. An analogous situation involves the question-mark, which is common in URLs. Introducing special-cases as proposed here greatly increases the cognitive load for the benefit of very few users and only a tiny fraction of the commands they execute. Doing this means you now have to document, and people have to remember, that echo a#b is quite different from echo a #b.

aca commented 11 months ago

I also don't think specification should change only because of single command. Hope anyone find some other cases or reasons to justify changes.

krader1961 commented 11 months ago

Please note, @aca, that the list of similar examples is huge. Consider the git CLI. That document doesn't cover the most commonly used meta-character in Git strings, the tilde, but you get the idea. Complicating the rules for what constitutes an Elvish bareword, makes it harder for people to interpret any given block of code. It's bad enough that ~ and = are already special-cased. I don't think we want to introduce more special-case rules for such characters.