mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-11-25 18:03:03 +01:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
911ebfd868 | ||
|
|
6b789c8bd6 | ||
|
|
984d07a53b |
@@ -1,6 +1,28 @@
|
|||||||
# Git version checking
|
# Git version checking
|
||||||
autoload -Uz is-at-least
|
autoload -Uz is-at-least
|
||||||
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
|
# Running `git version` forks on every startup, so cache the result for a day
|
||||||
|
# in $ZSH_CACHE_DIR, keyed on the resolved git binary's path and mtime.
|
||||||
|
() {
|
||||||
|
local cache="$ZSH_CACHE_DIR/git-version" git="${commands[git]:+${commands[git]:A}}" key magic
|
||||||
|
local -a stat lines
|
||||||
|
# Shims (scripts, or links to a non-git binary like mise) can dispatch to any git
|
||||||
|
[[ "${git:t:r}" = git ]] && read -r -k 2 -u 0 magic < "$git" 2>/dev/null
|
||||||
|
if [[ "${git:t:r}" = git && "$magic" != '#!' ]]; then
|
||||||
|
zmodload -F zsh/stat b:zstat
|
||||||
|
zstat -A stat +mtime -- "$git" 2>/dev/null
|
||||||
|
key="$git $stat[1]"
|
||||||
|
|
||||||
|
lines=("$cache"(Nm-1))
|
||||||
|
(( $#lines )) && lines=("${(@f)$(<"$cache")}")
|
||||||
|
if [[ "$lines[1]" = "$key" ]]; then
|
||||||
|
git_version="$lines[2]"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
|
||||||
|
[[ -z "$key" || ! -w "$ZSH_CACHE_DIR" ]] || print -rl -- "$key" "$git_version" >| "$cache"
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Functions Current
|
# Functions Current
|
||||||
|
|||||||
Reference in new issue
Block a user