mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-12 05:49:47 +08:00
Compare commits
5 Commits
7ef3f49f97
...
80a651a6df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80a651a6df | ||
|
|
56cfcb44e7 | ||
|
|
c262ffbb68 | ||
|
|
eafa78217d | ||
|
|
1ed8d4b555 |
12
lib/cli.zsh
12
lib/cli.zsh
@ -773,7 +773,17 @@ function _omz::theme::use {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _omz::update {
|
function _omz::update {
|
||||||
local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
|
# Check if git command is available
|
||||||
|
(( $+commands[git] )) || {
|
||||||
|
_omz::log error "git is not installed. Aborting..."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
|
||||||
|
[[ $? -eq 0 ]] || {
|
||||||
|
_omz::log error "\`$ZSH\` is not a git directory. Aborting..."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Run update script
|
# Run update script
|
||||||
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
autoload -Uz is-at-least
|
||||||
|
|
||||||
# The git prompt's git commands are read-only and should not interfere with
|
# The git prompt's git commands are read-only and should not interfere with
|
||||||
# other processes. This environment variable is equivalent to running with `git
|
# other processes. This environment variable is equivalent to running with `git
|
||||||
# --no-optional-locks`, but falls back gracefully for older versions of git.
|
# --no-optional-locks`, but falls back gracefully for older versions of git.
|
||||||
@ -37,8 +39,10 @@ function _omz_git_prompt_info() {
|
|||||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enable async prompt by default unless the setting is at false / no
|
# Use async version if setting is enabled, or undefined but zsh version is at least 5.0.6
|
||||||
if zstyle -T ':omz:alpha:lib:git' async-prompt; then
|
# https://github.com/ohmyzsh/ohmyzsh/issues/12331#issuecomment-2059460268
|
||||||
|
if zstyle -t ':omz:alpha:lib:git' async-prompt \
|
||||||
|
|| { is-at-least 5.0.6 && zstyle -T ':omz:alpha:lib:git' async-prompt }; then
|
||||||
function git_prompt_info() {
|
function git_prompt_info() {
|
||||||
setopt localoptions noksharrays
|
setopt localoptions noksharrays
|
||||||
if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]" ]]; then
|
if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]" ]]; then
|
||||||
|
|||||||
@ -4,14 +4,14 @@ function omz_history {
|
|||||||
local clear list stamp
|
local clear list stamp
|
||||||
zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp
|
zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ -n "$clear" ]]; then
|
||||||
# if no arguments provided, show full history starting from 1
|
|
||||||
builtin fc $stamp -l 1
|
|
||||||
elif [[ -n "$clear" ]]; then
|
|
||||||
# if -c provided, clobber the history file
|
# if -c provided, clobber the history file
|
||||||
echo -n >| "$HISTFILE"
|
echo -n >| "$HISTFILE"
|
||||||
fc -p "$HISTFILE"
|
fc -p "$HISTFILE"
|
||||||
echo >&2 History file deleted.
|
echo >&2 History file deleted.
|
||||||
|
elif [[ $# -eq 0 ]]; then
|
||||||
|
# if no arguments provided, show full history starting from 1
|
||||||
|
builtin fc $stamp -l 1
|
||||||
else
|
else
|
||||||
# otherwise, run `fc -l` with a custom format
|
# otherwise, run `fc -l` with a custom format
|
||||||
builtin fc $stamp -l "$@"
|
builtin fc $stamp -l "$@"
|
||||||
|
|||||||
@ -20,14 +20,16 @@ zstyle -s ':omz:update' mode update_mode || {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Cancel update if:
|
# Cancel update if:
|
||||||
# - the automatic update is disabled.
|
# - the automatic update is disabled
|
||||||
# - the current user doesn't have write permissions nor owns the $ZSH directory.
|
# - the current user doesn't have write permissions nor owns the $ZSH directory
|
||||||
# - is not run from a tty
|
# - is not run from a tty
|
||||||
# - git is unavailable on the system.
|
# - git is unavailable on the system
|
||||||
|
# - $ZSH is not a git repository
|
||||||
if [[ "$update_mode" = disabled ]] \
|
if [[ "$update_mode" = disabled ]] \
|
||||||
|| [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \
|
|| [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \
|
||||||
|| [[ ! -t 1 ]] \
|
|| [[ ! -t 1 ]] \
|
||||||
|| ! command git --version 2>&1 >/dev/null; then
|
|| ! command git --version 2>&1 >/dev/null \
|
||||||
|
|| (builtin cd -q "$ZSH"; ! command git rev-parse --is-inside-work-tree &>/dev/null); then
|
||||||
unset update_mode
|
unset update_mode
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -10,9 +10,14 @@ fi
|
|||||||
|
|
||||||
# Protect against unwanted sourcing
|
# Protect against unwanted sourcing
|
||||||
case "$ZSH_EVAL_CONTEXT" in
|
case "$ZSH_EVAL_CONTEXT" in
|
||||||
*:file) echo "error: this file should not be sourced" && return ;;
|
*:file) echo "error: this file should not be sourced" && return 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script
|
||||||
|
if [[ -z "$ZSH" ]]; then
|
||||||
|
ZSH="${0:a:h:h}"
|
||||||
|
fi
|
||||||
|
|
||||||
cd "$ZSH"
|
cd "$ZSH"
|
||||||
|
|
||||||
verbose_mode="default"
|
verbose_mode="default"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user