romkatv / zsh4humans

A turnkey configuration for Zsh
MIT License
1.81k stars 116 forks source link

refactor: make caret optional based on zstyle in comp files #324

Closed LangLangBart closed 2 months ago

LangLangBart commented 2 months ago

Description

This PR adds the ability to make the insertion of the anchored match character ^ in completions optional.

# disable the insertation of the anchored match character
zstyle ':z4h:fzf-complete' anchored-match-comp-words false
zstyle ':z4h:fzf-complete' anchored-match-comp-files false

Reason

For completing words, I prefer to have it disabled as I frequently press the backspace key and then enter words to search for a keyword in the description of flags. I thought adding an option would better serve my use case. The comp-files widget was modified only for completeness sake.

romkatv commented 2 months ago

The idea is that you can press SPACE if you want to type a keyword to search for, or just keep typing if you want to continue with the word you've already started. Have you tried that?

LangLangBart commented 2 months ago

Using SPACE works also, but I then have to press this additional character.

In the GIF below, I try to complete a flag with "civ", and using no anchor suits me better.

romkatv commented 2 months ago

When you type "-" and press TAB, the list contains only entries that start with "-". From your sceencast it appears as if you expect it too include all things that contain "-". It just so happens that the entry you are looking for in the screencast both starts with "-" and contains it in the middle. This isn't common. Do you have another use case?

LangLangBart commented 2 months ago

This isn't common. Do you have another use case?

When ignoring the case and making it not exact, it allows the description of the flag to be searched.

zstyle ':z4h:fzf-complete' fzf-flags --height '~20%'  --ignore-case --no-exact
zstyle ':z4h:fzf-complete' anchored-match-comp-words false
LangLangBart commented 2 months ago

The inserted ^ character was initially annoying when completing environment variables. Since fzf uses smart-case by default, completing uppercase variables requires uppercase input; --ignore-case addressed this.

Then, with flags for completion, it restricts itself to the exact word, so if you have typed the end of a long flag name, it won't show it to you, hence making the anchor optional.

romkatv commented 2 months ago

Is that what you actually want to do?

Do you see my point? The anchor is there for a good reason.

LangLangBart commented 2 months ago

Absolutely, I often see the point of including the anchor, but I find myself frequently annoyed by it, so I thought giving the user an easy option would be a good idea. However, based on your hesitation, I will maintain a local workaround and close this PR.

romkatv commented 2 months ago

That's fine with me. I can merge it if you submit the PR. It's making things inconsistent but won't burden me with extra maintenance.