acomagu / fish-async-prompt

Make your prompt asynchronous to improve the reactivity.
MIT License
389 stars 22 forks source link

FR: I'd like the prompt redrawn when the terminal with fish gains focus #77

Open ilyagr opened 1 month ago

ilyagr commented 1 month ago

I'd love the time and the current commit to be updated when I switch to a different shell.

This could be doable with the https://github.com/fish-shell/fish-shell/blob/8880fa8dd7f868f2c098b7b845caab2affc2e4f9/doc_src/language.rst?plain=1#L2095 event.

(Separately, an option to redraw the prompt every minute would also be nice. I can file a separate FR for this. #78 )

ilyagr commented 1 month ago

As far as I can tell, the following is "supposed" to work (see https://github.com/fish-shell/fish-shell/issues/6394#issuecomment-561810381), but doesn't with fish_async_prompt.

function fish_focus_in --on-event fish_focus_in
    commandline -f repaint
end

See also https://fishshell.com/docs/current/cmds/bind.html#special-input-functions for repaint and https://fishshell.com/docs/current/cmds/commandline.html

ilyagr commented 1 month ago

This seems to work (maybe?):

function fish_focus_in --on-event fish_focus_in
    __async_prompt_fire
    # commandline -f paint  # Not sure whether this helps or hurts.
end

Is this the correct way? I think it'd be nice if this was "officially" supported with a non-__ function.