Allow restricting abbreviations to specific commands (#10452)

This allows making something like

```fish
abbr --add gc --position anywhere --command git back 'reset --hard
HEAD^'
```

to expand "gc" to "reset --hard HEAD^", but only if the command is
git (including "command git gc" or "and git gc").

Fixes #9411
This commit is contained in:
Fabian Boehm
2024-04-24 18:09:04 +02:00
committed by GitHub
parent 16eeba8f65
commit 69583f3030
8 changed files with 105 additions and 19 deletions

View File

@@ -157,3 +157,29 @@ sendline(r"""abbr LLL --position anywhere --set-cursor=!HERE! '!HERE! | less'"""
expect_prompt()
send(r"""echo LLL derp?""")
expect_str(r"<echo derp | less >")
sendline(r"""abbr foo --command echo bar""")
expect_prompt()
sendline(r"""printf '%s\n' foo """)
expect_prompt("foo")
sendline(r"""echo foo """)
expect_prompt("bar")
sendline(r"""true; and echo foo """)
expect_prompt("bar")
sendline(r"""true; and builtin echo foo """)
expect_prompt("bar")
sendline(r"""abbr fruit --command={git,hg,svn} banana""")
expect_prompt()
sendline(r"""function git; echo git $argv; end; function hg; echo hg $argv; end; function svn; echo svn $argv; end""")
expect_prompt()
sendline(r"""git fruit""")
expect_prompt("git banana")
sendline(r"""abbr""")
expect_prompt("abbr -a --position anywhere --command git --command hg --command svn -- fruit banana")
sendline(r"""function banana; echo I am a banana; end""")
expect_prompt()
sendline(r"""abbr fruit --command={git,hg,svn,} banana""")
expect_prompt()
sendline(r"""fruit foo""")
expect_prompt("I am a banana")