fish-shell / fish-shell/fish-shell
abbr: command-list should be treated like multiple calls with a single `--command`
- Dominant language
- Rust
- Stars
- 34.2k
- Forks
- 2.4k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 13
Description
fish 4.5.0
### State of affairs
A call such as `abbr --command foo --command bar abv exp1`, will add the abbreviation (`abv`) to each individual given command (`cmd1` and `cmd2`), as if `abbr` was called for each individual command.
A call to `abbr` with the same abbreviation and the same command list will replace the existing entry in the abbreviation table.
A call to `abbr` with the same abbreviation but a different command list will add a new entry in the abbreviation table.
Then the expansion of an abbreviation for a given command will use the last entry in the table
### Result
- one cannot delete the abbreviation for a specific command if it was added with a command list:
```fish
> abbr --command={git,hg} co checkout
> abbr -e --command=hg co || echo failed
failed
```
One has to delete the whole command list and create a new one instead:
```fish
> abbr --command={git,hg} co checkout
> abbr -e --command={git,hg} co
> abbr --command=git co checkout
```
- Deleting an abbreviation may result in no-abbreviation or resurrecting an old one depending on the other entries in the table:
```fish
> abbr --command=git co checkout
> abbr --command={git,hg} co commit
> git co # expands to `commit`
> abbr -e --command={git,hg} co
> git co # still expands but to `checkout`
> abbr -e --command=git co
> git co # doesn't expand, as desired
```
- Worse, deleting an abbreviation may result in no change for a given command:
```fish
> abbr --command=git co checkout
> abbr --command={git,hg} co commit
> abbr -e --command=git co
> git co # still expands, and still to `commit`
```
### Opinion
I think it would be better and more intuitive if `abbr --command ... --command` was treated the same as `abbr --command ...; abbr --command ...`, except (maybe) it's atomic.
#### Note
For that matter, it is not obvious what `--command ... --command ...` is IMHO. My first guess was that it created an abbreviation for a sub-subcommand. I had to read the help and see the more telling `--command={...,...}` checkout example to really understand.
The current behavior is probably more useful (sub-subcommand are rare enough, and one would generally prefer an abbreviation that expands to `subcmd subsubcmd` rather than just `subsubcmd`) but I don't think it's the most intuitive.
And even the "more useful". how much is that in absolute terms? Version control tools are probably a poster child for this usage, but is it used elsewhere? And if it is, is it really advantageous compared to duplicating the call, or using a for-loop if there are a lot of common abbreviations?
TLDR; maybe multiple `--command` shouldn't even be supported?
Contributor guide
Research direction
Start at the abbr command's handling of repeated --command options and compare it with separate abbr calls. Confirm the intended semantics with maintainers, especially atomicity and whether multiple --command options should remain supported. Done means command-list additions and deletions behave consistently for each command, with the reported cases covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100