mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-25 13:30:07 +00:00
Squashed 'gitstatus/' changes from a827370d7..643091154
643091154 suppress rc files for curl and wget; see #146 git-subtree-dir: gitstatus git-subtree-split: 6430911548516bd9bb0e4a5088993302d45cc499
This commit is contained in:
parent
62c0a12a10
commit
9fd719c834
1 changed files with 94 additions and 66 deletions
160
install
160
install
|
@ -9,7 +9,7 @@ _gitstatus_install_main() {
|
||||||
set -u
|
set -u
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local argv1=$1
|
local argv1="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
local no_check= no_install= uname_s= uname_m= gitstatus_dir= dl_status=
|
local no_check= no_install= uname_s= uname_m= gitstatus_dir= dl_status=
|
||||||
|
@ -227,91 +227,107 @@ END
|
||||||
mkdir -p -- "$tmpdir" || return
|
mkdir -p -- "$tmpdir" || return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
|
||||||
|
>&2 echo "[gitstatus] error: please install curl or wget"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
(
|
(
|
||||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
run_cmd() {
|
||||||
builtin cd -q -- "$tmpdir" || exit
|
command -v "$1" >/dev/null 2>/dev/null || return 127
|
||||||
else
|
local trapped= pid die ret
|
||||||
cd -- "$tmpdir" || exit
|
trap 'trapped=1' $sig
|
||||||
fi
|
# The only reason for suppressing stderr is that `curl -f` cannot be silenced:
|
||||||
|
# `-s` doesn't work despite what the docs say.
|
||||||
local fetch
|
command "$@" 2>/dev/null &
|
||||||
if command -v curl >/dev/null 2>&1; then
|
ret="$?"
|
||||||
fetch="command curl -fsSL --"
|
if [ "$ret" = 0 ]; then
|
||||||
elif command -v wget >/dev/null 2>&1; then
|
pid="$!"
|
||||||
fetch="command wget -O- --"
|
die="trap - $sig; kill -- $pid 2>/dev/null; wait -- $pid 2>/dev/null; exit 1"
|
||||||
else
|
trap "$die" $sig
|
||||||
>&2 echo "[gitstatus] error: please install curl or wget"
|
[ -z "$trapped" ] || eval "$die"
|
||||||
exit 1
|
wait -- "$pid" 2>/dev/null
|
||||||
fi
|
ret="$?"
|
||||||
|
fi
|
||||||
local url1="https://github.com/romkatv/gitstatus/releases/download/$version/$file.tar.gz"
|
trap - $sig
|
||||||
local url2="https://gitee.com/romkatv/gitstatus/raw/release-$version/release/$file.tar.gz"
|
[ -z "$trapped" ] || exit
|
||||||
|
return "$ret"
|
||||||
|
}
|
||||||
|
|
||||||
check_sha256() {
|
check_sha256() {
|
||||||
local file="$1".tar.gz
|
local data_file="$tmpdir"/"$1".tar.gz
|
||||||
|
local hash_file="$tmpdir"/"$1".tar.gz.sha256
|
||||||
local hash=
|
local hash=
|
||||||
if command -v shasum >/dev/null 2>/dev/null; then
|
if command -v shasum >/dev/null 2>/dev/null; then
|
||||||
hash="$(command shasum -b -a 256 -- "$file")" || hash=
|
if run_cmd shasum -b -a 256 -- "$data_file" >"$hash_file"; then
|
||||||
hash="${hash%% *}"
|
IFS= read -r hash <"$hash_file" || hash=
|
||||||
|
hash="${hash%% *}"
|
||||||
|
fi
|
||||||
elif command -v sha256sum >/dev/null 2>/dev/null; then
|
elif command -v sha256sum >/dev/null 2>/dev/null; then
|
||||||
hash="$(command sha256sum -b -- "$file")" || hash=
|
if run_cmd sha256sum -b -- "$data_file" >"$hash_file"; then
|
||||||
hash="${hash%% *}"
|
IFS= read -r hash <"$hash_file" || hash=
|
||||||
|
hash="${hash%% *}"
|
||||||
|
fi
|
||||||
elif command -v sha256 >/dev/null 2>/dev/null; then
|
elif command -v sha256 >/dev/null 2>/dev/null; then
|
||||||
hash="$(command sha256 -- "$file" </dev/null)" || hash=
|
if run_cmd sha256 -- "$data_file" </dev/null >"$hash_file"; then
|
||||||
# Ignore sha256 output if it's from hashalot. It's incompatible.
|
IFS= read -r hash <"$hash_file" || hash=
|
||||||
if [ ${#hash} -lt 64 ]; then
|
# Ignore sha256 output if it's from hashalot. It's incompatible.
|
||||||
hash=
|
if [ ${#hash} -lt 64 ]; then
|
||||||
else
|
hash=
|
||||||
hash="${hash##* }"
|
else
|
||||||
|
hash="${hash##* }"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
[ "$1" = 1 -a -z "$hash" -o "$hash" = "$sha256" ]
|
[ "$1" = 1 -a -z "$hash" -o "$hash" = "$sha256" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local url1="https://github.com/romkatv/gitstatus/releases/download/$version/$file.tar.gz"
|
||||||
|
local url2="https://gitee.com/romkatv/gitstatus/raw/release-$version/release/$file.tar.gz"
|
||||||
local sig='INT QUIT TERM ILL PIPE'
|
local sig='INT QUIT TERM ILL PIPE'
|
||||||
|
|
||||||
fetch() {
|
fetch() {
|
||||||
local trapped=
|
|
||||||
trap 'trapped=1' $sig
|
|
||||||
if [ "$1" != 1 ] && command -v sleep >/dev/null 2>/dev/null; then
|
if [ "$1" != 1 ] && command -v sleep >/dev/null 2>/dev/null; then
|
||||||
sleep "$1"
|
if ! run_cmd sleep "$1"; then
|
||||||
fi
|
echo -n >"$tmpdir"/"$1".status
|
||||||
local part=0 url ret pid die
|
return 1
|
||||||
while true; do
|
|
||||||
if [ "$part" = 3 ]; then
|
|
||||||
ret=1
|
|
||||||
break
|
|
||||||
elif [ "$part" = 0 ]; then
|
|
||||||
url="$2"
|
|
||||||
else
|
|
||||||
url="$2"."$part"
|
|
||||||
fi
|
fi
|
||||||
{ $fetch "$url" >>"$1".tar.gz 2>/dev/null & } 2>/dev/null
|
fi
|
||||||
ret=$?
|
local cmd part url ret
|
||||||
[ "$ret" = 0 ] || break
|
for cmd in 'curl -q -fsSL' 'wget --no-config -qO-'; do
|
||||||
pid=$!
|
part=0
|
||||||
die="trap - $sig; kill -- $pid 2>/dev/null; exit 1"
|
while true; do
|
||||||
trap "$die" $sig
|
if [ "$part" = 2 ]; then
|
||||||
[ -z "$trapped" ] || eval "$die"
|
ret=1
|
||||||
wait -- "$pid" 2>/dev/null
|
break
|
||||||
|
elif [ "$part" = 0 ]; then
|
||||||
|
url="$2"
|
||||||
|
else
|
||||||
|
url="$2"."$part"
|
||||||
|
fi
|
||||||
|
run_cmd $cmd -- "$url" >>"$tmpdir"/"$1".tar.gz
|
||||||
|
ret="$?"
|
||||||
|
[ "$ret" = 0 ] || break
|
||||||
|
check_sha256 "$1" && break
|
||||||
|
part=$((part+1))
|
||||||
|
done
|
||||||
|
[ "$ret" = 0 ] && break
|
||||||
|
run_cmd rm -f -- "$tmpdir"/"$1".tar.gz && continue
|
||||||
ret="$?"
|
ret="$?"
|
||||||
trap - $sig
|
break
|
||||||
[ "$ret" = 0 ] || break
|
|
||||||
check_sha256 "$1" && break
|
|
||||||
part=$((part+1))
|
|
||||||
done
|
done
|
||||||
echo -n >"$1".status
|
echo -n >"$tmpdir"/"$1".status
|
||||||
return "$ret"
|
return "$ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
local trapped=
|
local trapped=
|
||||||
trap 'trapped=1' $sig
|
trap 'trapped=1' $sig
|
||||||
fetch 1 "$url1" &
|
fetch 1 "$url1" &
|
||||||
local pid1=$!
|
local pid1="$!"
|
||||||
fetch 2 "$url2" &
|
fetch 2 "$url2" &
|
||||||
local pid2=$!
|
local pid2="$!"
|
||||||
|
|
||||||
local die="trap - $sig; kill -- $pid1 $pid2 2>/dev/null; exit 1"
|
local die="trap - $sig; kill -- $pid1 $pid2 2>/dev/null; wait -- $pid1 $pid2 2>/dev/null; exit 1"
|
||||||
trap "$die" $sig
|
trap "$die" $sig
|
||||||
[ -z "$trapped" ] || eval "$die"
|
[ -z "$trapped" ] || eval "$die"
|
||||||
|
|
||||||
|
@ -323,27 +339,39 @@ END
|
||||||
elif command -v true >/dev/null 2>/dev/null; then
|
elif command -v true >/dev/null 2>/dev/null; then
|
||||||
command true
|
command true
|
||||||
fi
|
fi
|
||||||
if [ -n "$pid1" -a -e 1.status ]; then
|
if [ -n "$pid1" -a -e "$tmpdir"/1.status ]; then
|
||||||
wait -- "$pid1" 2>/dev/null
|
wait -- "$pid1" 2>/dev/null
|
||||||
local ret="$?"
|
local ret="$?"
|
||||||
pid1=
|
pid1=
|
||||||
if [ "$ret" = 0 ]; then
|
if [ "$ret" = 0 ]; then
|
||||||
[ -z "$pid2" ] || kill -- "$pid2" 2>/dev/null
|
if [ -n "$pid2" ]; then
|
||||||
|
kill -- "$pid2" 2>/dev/null
|
||||||
|
wait -- "$pid2" 2>/dev/null
|
||||||
|
fi
|
||||||
n=1
|
n=1
|
||||||
break
|
break
|
||||||
elif [ -z "$pid2" ]; then
|
elif [ -z "$pid2" ]; then
|
||||||
break
|
break
|
||||||
|
else
|
||||||
|
die="trap - $sig; kill -- $pid2 2>/dev/null; wait -- $pid2 2>/dev/null; exit 1"
|
||||||
|
trap "$die" $sig
|
||||||
fi
|
fi
|
||||||
elif [ -n "$pid2" -a -e 2.status ]; then
|
elif [ -n "$pid2" -a -e "$tmpdir"/2.status ]; then
|
||||||
wait -- "$pid2" 2>/dev/null
|
wait -- "$pid2" 2>/dev/null
|
||||||
local ret="$?"
|
local ret="$?"
|
||||||
pid2=
|
pid2=
|
||||||
if [ "$ret" = 0 ]; then
|
if [ "$ret" = 0 ]; then
|
||||||
[ -z "$pid1" ] || kill -- "$pid1" 2>/dev/null
|
if [ -n "$pid1" ]; then
|
||||||
|
kill -- "$pid1" 2>/dev/null
|
||||||
|
wait -- "$pid1" 2>/dev/null
|
||||||
|
fi
|
||||||
n=2
|
n=2
|
||||||
break
|
break
|
||||||
elif [ -z "$pid1" ]; then
|
elif [ -z "$pid1" ]; then
|
||||||
break
|
break
|
||||||
|
else
|
||||||
|
die="trap - $sig; kill -- $pid1 2>/dev/null; wait -- $pid1 2>/dev/null; exit 1"
|
||||||
|
trap "$die" $sig
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -358,7 +386,7 @@ END
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
command tar -xzf "$n".tar.gz || exit
|
command tar -C "$tmpdir" -xzf "$tmpdir"/"$n".tar.gz || exit
|
||||||
|
|
||||||
local tmpfile
|
local tmpfile
|
||||||
if ! command -v mktemp >/dev/null 2>&1 ||
|
if ! command -v mktemp >/dev/null 2>&1 ||
|
||||||
|
@ -366,7 +394,7 @@ END
|
||||||
tmpfile="$cache_dir"/gitstatusd.tmp.$$
|
tmpfile="$cache_dir"/gitstatusd.tmp.$$
|
||||||
fi
|
fi
|
||||||
|
|
||||||
command mv -f -- gitstatusd-* "$tmpfile" || exit
|
command mv -f -- "$tmpdir"/gitstatusd-* "$tmpfile" || exit
|
||||||
command mv -f -- "$tmpfile" "$cache_dir"/"$file" && exit
|
command mv -f -- "$tmpfile" "$cache_dir"/"$file" && exit
|
||||||
command rm -f -- "$cache_dir"/"$file"
|
command rm -f -- "$cache_dir"/"$file"
|
||||||
command mv -f -- "$tmpfile" "$cache_dir"/"$file" && exit
|
command mv -f -- "$tmpfile" "$cache_dir"/"$file" && exit
|
||||||
|
@ -374,7 +402,7 @@ END
|
||||||
exit 1
|
exit 1
|
||||||
)
|
)
|
||||||
|
|
||||||
local ret=$?
|
local ret="$?"
|
||||||
command rm -rf -- "$tmpdir"
|
command rm -rf -- "$tmpdir"
|
||||||
[ "$ret" = 0 ] || return
|
[ "$ret" = 0 ] || return
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue