junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.91k stars 2.34k forks source link

sudo -E env kill <tab> does not invoke fzf completion #2130

Open MenkeTechnologies opened 3 years ago

MenkeTechnologies commented 3 years ago

Info

Problem / Steps to reproduce

sudo -E env kill does not invoke fzf completion.

junegunn commented 3 years ago

Related: #1992

Thanks for the PR. Excluding a set of commands won't fix #1992 so I'd like to find a more generic solution.

MenkeTechnologies commented 3 years ago

solving #1992 wont fix this either. I agree excluding certain words is a bad idea but not sure how to find best solution.

MenkeTechnologies commented 3 years ago

I have a very similar issue here that I solved for most use cases

https://github.com/MenkeTechnologies/zsh-expand/blob/master/zsh-expand.plugin.zsh#L5.

I loop through each word from the beginning, applying regex until I found the last word that is the final command to be executed. Its kind of complicated for example to pass over options that arguments after space.

First Thing was to pull off the current statement of the command line where the cursor is. you are not doing this. Causes of #1992.

ie.

for (( i = $#mywordsleft; i >= 0; i-- )); do
            # ;; ; | || && are partition separating chars
            # we will split the commad line and get the partition of the caret
            # aliases are valid in the first position after these chars
            case $mywordsleft[$i] in
                ';;' | \; | \| | '||' | '&&')
                    firstIndex=$((i+1))
                    break
                    ;;
                *)
                    ;;
            esac
        done
for (( i = 0; i < $#mywordsright; i++ )); do
            case $mywordsright[$i] in
                # ;; ; | || && are partition separating chars
                # we will split the commad line and get the partition of the caret
                # aliases are valid in the first position after these chars
                ';;' | \; | \| | '||' | '&&') lastIndex=$((i-1))
                break
                ;;
            *)
                ;;
        esac

All of this was for alias expansion on spacebar. Maybe too much for fzf project.

For example pwd; sudo -E env -S command gst => expands to => pwd; sudo -E env -S command git status

Havent heard of a more robust solution.