Avoid executing kitty just to read installed kitty version
This commit is contained in:
parent
69efd9801b
commit
b3fc2cb118
@ -6,7 +6,7 @@
|
||||
die() { printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr; exit 1; }
|
||||
|
||||
exec_kitty() {
|
||||
exec "$kitty_exe" "$@"
|
||||
[ -n "$kitty_exe" ] && exec "$kitty_exe" "$@"
|
||||
die "Failed to execute kitty"
|
||||
}
|
||||
|
||||
@ -14,15 +14,17 @@ script_path=$(command readlink -f "$0" 2> /dev/null)
|
||||
[ $? == 0 ] || script_path="$0"
|
||||
script_dir=$(command dirname "$script_path")
|
||||
install_dir="$(command dirname "$script_dir")/install"
|
||||
local_kitty_version_file="$install_dir/installed-kitty-version"
|
||||
kitty_exe="$install_dir/bin/kitty"
|
||||
if [ -e "$kitty_exe" ]; then
|
||||
local_kitty_version=$("$kitty_exe" +runpy "from kitty.constants import str_version; print(str_version)")
|
||||
if [ -r "$local_kitty_version_file" -a -f "$local_kitty_version_file" ]; then
|
||||
if [ $? = 0 ]; then
|
||||
version_sort_key() {
|
||||
printf "%05d%05d%05d" $(echo "$1" | command tr '.' '\n' | command head -n 3)
|
||||
}
|
||||
remote_kitty_version=$(command cat "$script_dir"/../version)
|
||||
remote_kitty_version=$(command cat "$script_dir/../version")
|
||||
[ $? = 0 ] || die "Failed to read remote kitty version"
|
||||
local_kitty_version=$(command cat "$local_kitty_version_file")
|
||||
[ $? = 0 ] || die "Failed to read local kitty version"
|
||||
[ $(version_sort_key "$remote_kitty_version") -le $(version_sort_key "$local_kitty_version") ] && exec_kitty "$@"
|
||||
fi
|
||||
fi
|
||||
@ -51,7 +53,7 @@ case "$(command uname)" in
|
||||
*) die "kitty pre-built binaries are not available for the $(command uname) operating system";;
|
||||
esac
|
||||
|
||||
release_version=$(fetch_quiet "https://api.github.com/repos/kovidgoyal/kitty/releases/latest" | command grep tag_name | command cut -dv -f2 | command cut -d '"' -f1)
|
||||
release_version=$(fetch_quiet "https://api.github.com/repos/kovidgoyal/kitty/releases/latest" | command grep tag_name | command head -n1 | command cut -dv -f2 | command cut -d '"' -f1)
|
||||
[ -z "$release_version" ] && die "Could not get kitty latest release version"
|
||||
command rm -rf "$install_dir"
|
||||
|
||||
@ -89,4 +91,5 @@ else
|
||||
command mkdir "$install_dir/bin"
|
||||
command ln -sf "$install_dir/kitty.app/Contents/MacOS/kitty" "$install_dir/bin/kitty"
|
||||
fi
|
||||
command "$kitty_exe" +runpy "from kitty.constants import str_version; print(end=str_version)" > "$local_kitty_version_file"
|
||||
exec_kitty "$@"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user