Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add menu completion for --position=anywhere abbrs in non-command position#12764

Closed
g0t4 wants to merge 3 commits into
fish-shell:masterfish-shell/fish-shell:masterfrom
g0t4:feature-complete-abbr-in-non-command-positiong0t4/fish-shell:feature-complete-abbr-in-non-command-positionCopy head branch name to clipboard
Closed

Add menu completion for --position=anywhere abbrs in non-command position#12764
g0t4 wants to merge 3 commits into
fish-shell:masterfish-shell/fish-shell:masterfrom
g0t4:feature-complete-abbr-in-non-command-positiong0t4/fish-shell:feature-complete-abbr-in-non-command-positionCopy head branch name to clipboard

Conversation

@g0t4

@g0t4 g0t4 commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Current tab completion behavior: abbrs can only be completed in command position (non-regex abbrs)

Desired behvaior: add completion for non-command position which would only apply to abbrs with --position=anywhere

Examples

## command only example:
abbr -- gst "git status"
# equivalent to:
abbr --position=command -- gst "git status"
# gst will show in menu completion when I do this:
gs<TAB>

## anywhere example:
abbr --position=anywhere -- pgr "| grep -i"
# intended use:
cat foo.log pgr<SPACE>
# expands to: 
cat foo.log | grep -i

# currently `pgr` shows during completion in command position only (although in this case, not useful in command position)
# I would like to see `pgr` show as a completion choice in non-command position:
cat foo.log pg<TAB>

# Why? I have many `p`/`pg` prefixed abbrs, completion would let me query the list as I add new choices to learn them!
# similar anywhere abbrs:
abbr -a --position anywhere -- pbat '| bat -l'
abbr -a --position anywhere -- pgr '| rg_grep -i'
abbr -a --position anywhere -- pgrv '| rg_grep -i --invert-match'
abbr -a --position anywhere -- phelp '| bat -l help'
abbr -a --position anywhere -- pini '| bat -pl ini'
abbr -a --position anywhere -- pjq '| jq .'
abbr -a --position anywhere -- pjqr '| jq -r .'
abbr -a --position anywhere -- pjqj '| jq --join-output .'
abbr -a --position anywhere -- pmd '| bat -pl md'
abbr -a --position anywhere -- prb '| bat -pl rb'
abbr -a --position anywhere -- psh '| bat -pl sh'
abbr -a --position anywhere -- pxml '| bat -l xml'
abbr -a --position anywhere -- pyml '| bat -l yml'
abbr -a --position anywhere -- puniq '| sort | uniq -c'
abbr -a --position anywhere -- psort '| sort -h'

another good use case in this set... `pj<TAB>` to see all my jq related pipe abbrs

right now if I don't know the exact abbr in non-command position, I can't use the abbr... but when I am learning abbrs, if I can tab complete to see choices, that helps me learn

Changes

  • BTW, existing abbr completion works for command position only.

  • I added a boolean parameter is_command_position to complete_abbr(&mut self, cmd: WString, is_command_position: bool)

  • is_command_position = false triggers existing command position completion.

  • is_command_position = true triggers the new, non-command position completion which means only abbrs that have --position=anywhere

  • In all cases, regex based abbrs are excluded, preserving existing behavior.

  • I added three tests using my pgr example, see ./tests/checks/complete.fish

TODOs:

  • [ n/a ] If addressing an issue, a commit message mentions Fixes issue #<issue-number>
  • [ n/a ] Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • [ n/a ] User-visible changes noted in CHANGELOG.rst

g0t4 and others added 3 commits May 18, 2026 12:31
Abbreviations with `--position anywhere` now appear in the completion
menu when tabbing in argument position (e.g. `cat foo.log pg<TAB>`
shows pgr, pgrv, pjq, etc.), not just in command position.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@faho

faho commented May 18, 2026

Copy link
Copy Markdown
Member

#12630 is going to outlaw AI-authored commits, so this would be against policy.

@faho faho closed this May 18, 2026
@fish-shell fish-shell locked as spam and limited conversation to collaborators May 18, 2026
@g0t4
g0t4 deleted the feature-complete-abbr-in-non-command-position branch May 20, 2026 18:46
@g0t4 g0t4 mentioned this pull request May 20, 2026
4 tasks
@fish-shell fish-shell unlocked this conversation Jun 2, 2026
krobelus pushed a commit that referenced this pull request Jun 2, 2026
Make abbreviations with `--position anywhere` appear in the completion
menu when tabbing in argument position (e.g. `cat foo.log pg<TAB>`
shows pgr, pgrv, pjq, etc.), not just in command position.

Lift "do_file" into an enum, so we don't have to check "is_redirection"
twice, and can express more accurately the reason for not completing
abbreviations after redirection.

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Closes #12764
@krobelus

krobelus commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Sorry I had missed this one.
Looks good overall. You should have squashed the commits into one, to reduce noise.
Merged as 4b2aba3.
Instead of checking is_redirection twice, I introduced a new enum; I think that makes sense?
(Also there was a test failure triggered by cargo xtask check, fixed with 71ce491 (abbr unit tests: remove abbreviations after test, 2026-06-02).)

@g0t4

g0t4 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@krobelus

👍 I like the DoFile::Only

  • deduplicates the condition that's effectively tested twice in my version
  • makes explicit a third state for do_file
  • all the spots that use do_file are easier to read now

Thanks for cleaning that up... this is a game changer for how I use abbrs!

will do on squash next time

@injust

injust commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@krobelus BTW #12630 is linked in the 4.8.0 release notes instead of this PR.

@injust

injust commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

I think this is a much more breaking change than expected, see #12838.

EDIT: This was reverted in 2c17c96.

@mikelei8291

Copy link
Copy Markdown
Contributor

Turns out AI slop always makes things worse, lol. Even if it's not just about the quality of the code, AI makes people think less before implementing anything. Fixing one thing while creating several more new bugs, or adding a new feature that breaks several existing features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.