gazorby / fish-abbreviation-tips

💡 Help you remembering your abbreviations
MIT License
291 stars 7 forks source link

Don't show tips when history is used #15

Open mamiu opened 3 years ago

mamiu commented 3 years ago

I usually use the history a lot. (E.g. the up arrow key or CTRLR from fzf)

But when using the history I don't want to see the tips.

Is that already possible and if so how?

gazorby commented 3 years ago

Hi @mamiu!

Currently the plugin doesn't remember how abbreviations are triggered, so it's not possible for now.

I'm also interested in this feature, I'll take a look at it when I have some time.

mamiu commented 3 years ago

@gazorby Ok get it. Thanks for taking care of it.

I just played around right now and found a workaround which works, but is probably not the best solution.

In the fish_user_key_bindings.fish file add a wrapper for the history-search-backward special input function which sets the __abbr_tips_used variable to 1 before calling the history-search-backward function. Then adjust all keybindings that use the history-search-backward function so that they use the wrapper instead.

# history-search-backward wrapper for the fish-abbreviation-tips plugin
function __abbr_tips_history_backward
    set -g __abbr_tips_used 1
    commandline -f history-search-backward
end

# user defined key bindings
function fish_user_key_bindings
    bind \e\[A __abbr_tips_history_backward # arrow up key
    # If you use other key bindings that use the history-search-backward function make sure they also call the custom __abbr_tips_history_backward function
end
doubledup commented 1 year ago

This also affects custom keybindings that add a command that has an abbreviation. eg. I use \co to open my editor, passing the contents of the line as arguments:

set -x EDITOR 'nvim'
# ...
abbr nv "$EDITOR"
# ...
bind \co "commandline -i ' $EDITOR '; commandline -f backward-kill-word beginning-of-line yank execute"

But __abbr_tips_used also works here:

function launch_editor
    set -g __abbr_tips_used 1
    commandline -i " $EDITOR "
    commandline -f backward-kill-word beginning-of-line yank execute
end
bind \co launch_editor