kitty/shell-integration/ssh/kitty
OBrutus a0978a74a2 remote_file kitten: port ask UI to Go, wrap and shrink Python to result-handler shim
Adds kittens/remote_file/main.go (ask menu, hostname-mismatch prompt,
save-path prompt with tab completion, edit/open/save actions) on top of the
ControlMaster/ssh helpers from the previous two commits, registers it in
tools/cmd/tool/main.go, and adds remote_file to shell-integration/ssh/kitty's
wrapped_kittens list so both `kitty +kitten remote_file` and ssh-session
invocations exec the Go binary directly. main.py is shrunk to option_text
(kept importable by kitty/cli_stub.py and used for --doc/--help generation),
is_ssh_kitten_sentinel (kept importable by kitty/window.py), and the
handle_result shim boss.py runs in-process to open the returned file.

Also drops the dead `-h` alias on --hostname: Python's CLI layer always
special-cases -h/--help ahead of user options, so it never worked as a
hostname shorthand, but the Go CLI layer hard-errors on the collision; removing
it is a no-op for existing behavior (boss.py only ever passes --hostname) and
unblocks `kitten remote-file --help`. Also adds the same reset_terminal()
calls Python makes between UI phases (ask menu -> action, hostname-mismatch
prompt, overwrite prompt, $EDITOR handoff) so the Go and Python screens match.

Manually verified parity against Python (ask menu, cancel, open/edit/save
download+upload round-trips, hostname-mismatch Y/N, save-path prompt and
overwrite O/A/R/N) using a fake-ssh test double, and confirmed post-wrap that
`kitty +kitten remote_file` execs the Go kitten binary.
2026-08-13 15:21:57 +05:30

134 lines
4.3 KiB
Bash
Executable file

#!/bin/sh
# Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net>
#
# Distributed under terms of the GPLv3 license.
{ \unalias command; \unset -f command; } >/dev/null 2>&1
die() { printf "\033[31m%s\033[m\n\r" "$*" > /dev/stderr; exit 1; }
delete_lock_dir() {
trap '' EXIT INT QUIT TERM
[ -n "$lock_dir" ] && {
command rm -rf "$lock_dir"
lock_dir=""
}
}
exec_kitty() {
delete_lock_dir
[ -n "$kitty_exe" ] && exec "$kitty_exe" "$@"
die "Failed to execute kitty"
}
is_wrapped_kitten() {
wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key transfer query_terminal choose-files command-palette resize_window broadcast remote_file"
[ -n "$1" ] && {
case " $wrapped_kittens " in
*" $1 "*) printf "%s" "$1" ;;
esac
}
}
test "(" "$1" = "+kitten" -a -n "$(is_wrapped_kitten "$2")" ")" -o "(" "$1" = "+" -a "$2" = "kitten" -a "$(is_wrapped_kitten "$3")" ")" && {
if [ "$1" = "+kitten" ]; then shift "1"; else shift "2"; fi
exec kitten "$@"
}
lock_dir=""
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"
remote_kitty_version_file="$script_dir/../version"
local_kitty_version_file="$install_dir/installed-kitty-version"
kitty_exe="$install_dir/bin/kitty"
local_kitty_version=""
[ -f "$kitty_exe" -a -x "$kitty_exe" -a "$1" != "+update-kitty" ] && exec_kitty "$@"
case "$(command uname)" in
'Linux') OS="linux";;
'Darwin') OS="macos";;
*) die "kitty pre-built binaries are not available for the $(command uname) operating system";;
esac
if command -v curl 2> /dev/null > /dev/null; then
fetch() {
command curl -fL "$1"
}
fetch_quiet() {
command curl -fsSL "$1"
}
elif command -v wget 2> /dev/null > /dev/null; then
fetch() {
command wget -O- "$1"
}
fetch_quiet() {
command wget --quiet -O- "$1"
}
else
die "Neither curl nor wget available, cannot download kitty"
fi
if [ "$OS" = "linux" ]; then
case "$(command uname -m)" in
amd64|x86_64) arch="x86_64";;
aarch64*) arch="arm64";;
armv8*) arch="arm64";;
arm64) arch="arm64";;
i386) arch="i686";;
i686) arch="i686";;
*) die "Unknown CPU architecture $(command uname -m)";;
esac
fi
release_version=$(fetch_quiet "https://sw.kovidgoyal.net/kitty/current-version.txt")
[ $? -ne 0 -o -z "$release_version" ] && {
[ -n "$local_kitty_version" ] && exec_kitty "$@"
die "Could not get kitty latest release version"
}
if [ "$OS" = "linux" ]; then
url="https://github.com/kovidgoyal/kitty/releases/download/v$release_version/kitty-$release_version-$arch.txz"
else
url="https://github.com/kovidgoyal/kitty/releases/download/v$release_version/kitty-$release_version.dmg"
fi
lock_dir="$script_dir/kitty-install-lock"
if ! command mkdir "$lock_dir" 2> /dev/null; then
ed="$lock_dir"
lock_dir="";
die "Failed to create lock dir another instance of the kitty bootstrap script is running. If you are sure that is not the case delete: $ed";
fi
trap 'delete_lock_dir' EXIT INT QUIT TERM
printf "\033[33mkitty needs to be installed\033[m\n\n"
command rm -rf "$install_dir"
command mkdir -p "$install_dir"
printf "Downloading kitty from: \033[32m%s\033[m\n\n" "$url"
if [ "$OS" = "linux" ]; then
old_umask=$(umask)
umask 000
fetch "$url" | command tar -C "$install_dir" -xJof -
umask "$old_umask"
[ $? = 0 ] || die "Failed to download and install kitty"
else
tdir=$(command mktemp -d "$install_dir/tmp-for-dmg-XXXXXXXXXXXX")
[ $? = 0 ] || die "Creating temp directory failed"
fetch "$url" > "$tdir/kitty.dmg"
command mkdir "$tdir/mp"
command hdiutil attach "$tdir/kitty.dmg" "-mountpoint" "$tdir/mp" || die "Failed to mount kitty.dmg"
command ditto -v "$tdir/mp/kitty.app" "$install_dir/kitty.app"
rc="$?"
command hdiutil detach "$tdir/mp"
command rm -rf "$tdir"
[ "$rc" != "0" ] && die "Failed to copy kitty.app from mounted dmg"
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 "$@"