Make your prompt asynchronous in Fish.
We run your fish_prompt
and fish_right_prompt
functions 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 <prompt-func-name>_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 grayed 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_prompt
or 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
end
function 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.
Define variables inherited to prompt functions. Set all
to pass all global variables.
Default: status pipestatus SHLVL CMD_DURATION fish_bind_mode
Example:
set -U async_prompt_inherit_variables all
Define functions replaced to run asynchronously. Usually one or both of fish_prompt
and fish_right_prompt
.
Other functions can be specified, but they must be called from fish_prompt
or fish_right_prompt
and function arguments can't be passed to it.
Default: fish_prompt fish_right_prompt
Example:
set -U async_prompt_functions fish_right_prompt
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
This flag specifies whether to disown a subprocess for prompt rendering. Setting this flag to 0
may result in errors such as There are still jobs active
when executing the exit command. Please refer to #67 for why this flag was introduced.
Default: 1
Set 0 to disable async-prompt completely. (It does not respond to changes made after the plugin has been loaded.)
Default: 1
Example:
if test "$TERM_PROGRAM" = WarpTerminal
set -g async_prompt_enable 0
end