1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-02-12 05:49:47 +08:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Loïc Yhuel
04007a0e5d
feat(git): implement async completion for git_prompt_status (#12319)
This is important for themes using it, since it is usually a little slower than git_prompt_info.

Also two small fixes :
 - the handler for git_prompt_info was incorrectly named _omz_git_prompt_status
 - _defer_async_git_register was kept in precmd, there is no need to call it on each prompt
2024-04-03 21:32:16 +02:00
Marc Cornellà
ec1afe9dd6
feat(git)!: enable async git prompt (now for real)
BREAKING CHANGE: the new async prompt feature will render prompt information
asyncronously and degrade nicely when the calls take too long to finish, as
the prompt will already be first drawn and interactive. This is
enabled by default for the git prompt and themes that use it (`git_prompt_info`).
If you find that it's not working for you, please open an issue if one is
not already opened, and see https://github.com/ohmyzsh/ohmyzsh#disable-async-git-prompt
for how to turn it off.
2024-04-03 20:09:19 +02:00
Loïc Yhuel
b43b84abc7
fix(async): avoid blocking the shell while waiting (#12304)
Co-authored-by: Marc Cornellà <marc@mcornella.com>
2024-04-03 19:42:47 +02:00
Gregory Reshetniak
130002a79e
feat(httpie): complete https command (#12314) 2024-04-03 09:10:33 +02:00
4 changed files with 36 additions and 14 deletions

View File

@ -43,6 +43,7 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi
- [Custom Plugins And Themes](#custom-plugins-and-themes) - [Custom Plugins And Themes](#custom-plugins-and-themes)
- [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems) - [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems)
- [Skip Aliases](#skip-aliases) - [Skip Aliases](#skip-aliases)
- [Disable async git prompt](#disable-async-git-prompt)
- [Getting Updates](#getting-updates) - [Getting Updates](#getting-updates)
- [Updates Verbosity](#updates-verbosity) - [Updates Verbosity](#updates-verbosity)
- [Manual Updates](#manual-updates) - [Manual Updates](#manual-updates)
@ -361,6 +362,17 @@ Instead, you can now use the following:
zstyle ':omz:lib:directories' aliases no zstyle ':omz:lib:directories' aliases no
``` ```
### Disable async git prompt
Async prompt functions are an experimental feature (included on April 3, 2024) that allows Oh My Zsh to render prompt information
asyncronously. This can improve prompt rendering performance, but it might not work well with some setups. We hope that's not an
issue, but if you're seeing problems with this new feature, you can turn it of by setting the following in your .zshrc file,
before Oh My Zsh is sourced:
```sh
zstyle ':omz:alpha:lib:git' async-prompt no
```
#### Notice <!-- omit in toc --> #### Notice <!-- omit in toc -->
> This feature is currently in a testing phase and it may be subject to change in the future. > This feature is currently in a testing phase and it may be subject to change in the future.

View File

@ -82,10 +82,8 @@ function _omz_async_request {
exec {fd}< <( exec {fd}< <(
# Tell parent process our PID # Tell parent process our PID
builtin echo ${sysparams[pid]} builtin echo ${sysparams[pid]}
# Store handler name for callback
builtin echo $handler
# Set exit code for the handler if used # Set exit code for the handler if used
(exit $ret) () { return $ret }
# Run the async function handler # Run the async function handler
$handler $handler
) )
@ -98,8 +96,7 @@ function _omz_async_request {
command true command true
# Save the PID from the handler child process # Save the PID from the handler child process
read pid <&$fd read -u $fd "_OMZ_ASYNC_PIDS[$handler]"
_OMZ_ASYNC_PIDS[$handler]=$pid
# When the fd is readable, call the response handler # When the fd is readable, call the response handler
zle -F "$fd" _omz_async_callback zle -F "$fd" _omz_async_callback
@ -114,15 +111,14 @@ function _omz_async_callback() {
local err=$2 # Second arg will be passed in case of error local err=$2 # Second arg will be passed in case of error
if [[ -z "$err" || "$err" == "hup" ]]; then if [[ -z "$err" || "$err" == "hup" ]]; then
# Get handler name from first line # Get handler name from fd
local handler local handler="${(k)_OMZ_ASYNC_FDS[(r)$fd]}"
read handler <&$fd
# Store old output which is supposed to be already printed # Store old output which is supposed to be already printed
local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}" local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}"
# Read output from fd # Read output from fd
_OMZ_ASYNC_OUTPUT[$handler]="$(cat <&$fd)" IFS= read -r -u $fd -d '' "_OMZ_ASYNC_OUTPUT[$handler]"
# Repaint prompt if output has changed # Repaint prompt if output has changed
if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then

View File

@ -9,7 +9,7 @@ function __git_prompt_git() {
GIT_OPTIONAL_LOCKS=0 command git "$@" GIT_OPTIONAL_LOCKS=0 command git "$@"
} }
function _omz_git_prompt_status() { function _omz_git_prompt_info() {
# If we are on a folder not tracked by git, get out. # If we are on a folder not tracked by git, get out.
# Otherwise, check for hide-info at global and local repository level # Otherwise, check for hide-info at global and local repository level
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \ if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
@ -38,8 +38,14 @@ function _omz_git_prompt_status() {
} }
# Enable async prompt by default unless the setting is at false / no # Enable async prompt by default unless the setting is at false / no
if zstyle -t ':omz:alpha:lib:git' async-prompt; then if zstyle -T ':omz:alpha:lib:git' async-prompt; then
function git_prompt_info() { function git_prompt_info() {
if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]" ]]; then
echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]"
fi
}
function git_prompt_status() {
if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" ]]; then if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" ]]; then
echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]"
fi fi
@ -51,8 +57,13 @@ if zstyle -t ':omz:alpha:lib:git' async-prompt; then
# Check if git_prompt_info is used in a prompt variable # Check if git_prompt_info is used in a prompt variable
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in case "${PS1}:${PS2}:${PS3}:${PS4}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
*(\$\(git_prompt_info\)|\`git_prompt_info\`)*) *(\$\(git_prompt_info\)|\`git_prompt_info\`)*)
_omz_register_handler _omz_git_prompt_info
;;
esac
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
*(\$\(git_prompt_status\)|\`git_prompt_status\`)*)
_omz_register_handler _omz_git_prompt_status _omz_register_handler _omz_git_prompt_status
return
;; ;;
esac esac
@ -65,6 +76,9 @@ if zstyle -t ':omz:alpha:lib:git' async-prompt; then
precmd_functions=(_defer_async_git_register $precmd_functions) precmd_functions=(_defer_async_git_register $precmd_functions)
else else
function git_prompt_info() { function git_prompt_info() {
_omz_git_prompt_info
}
function git_prompt_status() {
_omz_git_prompt_status _omz_git_prompt_status
} }
fi fi
@ -197,7 +211,7 @@ function git_prompt_long_sha() {
SHA=$(__git_prompt_git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" SHA=$(__git_prompt_git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
} }
function git_prompt_status() { function _omz_git_prompt_status() {
[[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return
# Maps a git status prefix to an internal constant # Maps a git status prefix to an internal constant

View File

@ -1,4 +1,4 @@
#compdef http #compdef http https
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2015 GitHub zsh-users - http://github.com/zsh-users # Copyright (c) 2015 GitHub zsh-users - http://github.com/zsh-users
# All rights reserved. # All rights reserved.