Search code examples
fish

Function bound to a key in Fish shell requires me to press enter, how to avoid that?


I have the following fish shell function

# gohome.fish
function gohome
    cd ~
end

When I bind it with bind \eg gohome and press Alt+G I still have to press enter to invoke it. Is it possible to execute gohome immediately upon pressing Alt+G?


Solution

  • When I bind it with bind \eg gohome and press Alt+G I still have to press enter to invoke it.

    You don't. The function is executed as soon as you press the key.

    What happens is that your prompt isn't repainted to update the current directory, and pressing enter triggers that.

    Do commandline -f repaint either in

    bind \eg 'gohome; commandline -f repaint'
    

    or in the function.