Make your prompt asynchronous to improve the reactivity.
Make your prompt asynchronous in Fish.
We run your
fish_promptand
fish_right_promptfunctions as a separate process to update your prompt asynchronously.
With Fisher:
$ fisher install acomagu/fish-async-prompt
By default, it prints the previous prompt until the new one is ready. But you can change it to any other string. Define a function which named
_loading_indicator, like
fish_prompt_loading_indicator.
For example, to show
…as the indicator of right prompt:
function fish_right_prompt_loading_indicator echo (set_color '#aaa')' … '(set_color normal) end
You can also use the previous prompt string because the function receives it as the first argument. For example, show previous prompt but glayed out:
function fish_right_prompt_loading_indicator -a last_prompt echo -n "$last_prompt" | sed -r 's/\x1B\[[0-9;]*[JKmsu]//g' | read -zl uncolored_last_prompt echo -n (set_color brblack)"$uncolored_last_prompt"(set_color normal) end
The loading indicator can be set up not only for
fish_promptor
fish_right_prompt, but also for other function, if you specify it in
async_prompt_functions. e.g.
function _git_branch_name sleep 1 # For demo. git symbolic-ref --short HEAD ^/dev/null endfunction fish_right_prompt echo (set_color 88f)(_git_branch_name) (set_color cyan)(prompt_pwd) end
Async prompt setup.
set async_prompt_functions _git_branch_name
function _git_branch_name_loading_indicator echo (set_color brblack)…(set_color normal) end
If you have problems, try changing the values of these variables. When you change the configurations, please restart your shell.
async_prompt_inherit_variables
Define variables inherited to prompt functions. Set
allto pass all global variables.
Default:
status SHLVL CMD_DURATION
Example:
set -U async_prompt_inherit_variables all
async_prompt_functions
Define functions replaced to run asynchronously. Usually one or both of
fish_promptand
fish_right_prompt.
Other functions can be specified, but they must be called from
fish_promptor
fish_right_promptand function arguments can't be passed to it.
Default:
fish_prompt fish_right_prompt
Example:
set -U async_prompt_functions fish_right_prompt
async_prompt_internal_signal
fish-async-prompt uses SIGUSR1 to communicate with the spawned process by default. If it conflicts with other plugin/program, try changing this.
Default:
SIGUSR1
Example:
set -U async_prompt_internal_signal SIGUSR2