This commit is contained in:
Kovid Goyal 2022-03-23 18:19:12 +05:30
commit c41405fd57
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 19 additions and 11 deletions

View File

@ -358,6 +358,15 @@ def get_connection_data(args: List[str], cwd: str = '', extra_args: Tuple[str, .
host_name = arg host_name = arg
if not host_name: if not host_name:
return None return None
if host_name.startswith('ssh://'):
from urllib.parse import urlparse
purl = urlparse(host_name)
if purl.hostname:
host_name = purl.hostname
if purl.username:
host_name = f'{purl.username}@{host_name}'
if port is None and purl.port:
port = purl.port
if identity_file: if identity_file:
if not os.path.isabs(identity_file): if not os.path.isabs(identity_file):
identity_file = os.path.expanduser(identity_file) identity_file = os.path.expanduser(identity_file)
@ -466,7 +475,7 @@ def wrap_bootstrap_script(sh_script: str, interpreter: str) -> List[str]:
def get_remote_command( def get_remote_command(
remote_args: List[str], ssh_opts: SSHOptions, hostname: str = 'localhost', cli_hostname: str = '', cli_uname: str = '', remote_args: List[str], ssh_opts: SSHOptions, cli_hostname: str = '', cli_uname: str = '',
echo_on: bool = True, request_data: bool = False echo_on: bool = True, request_data: bool = False
) -> Tuple[List[str], Dict[str, str], str]: ) -> Tuple[List[str], Dict[str, str], str]:
interpreter = ssh_opts.interpreter interpreter = ssh_opts.interpreter
@ -579,13 +588,13 @@ def run_ssh(ssh_args: List[str], server_args: List[str], found_extra_args: Tuple
if hostname.startswith('ssh://'): if hostname.startswith('ssh://'):
from urllib.parse import urlparse from urllib.parse import urlparse
purl = urlparse(hostname) purl = urlparse(hostname)
hostname_for_match = purl.hostname or hostname hostname_for_match = purl.hostname or hostname[6:].split('/', 1)[0]
uname = purl.username or uname uname = purl.username or uname
elif '@' in hostname and hostname[0] != '@': elif '@' in hostname and hostname[0] != '@':
uname, hostname_for_match = hostname.split('@', 1) uname, hostname_for_match = hostname.split('@', 1)
else: else:
hostname_for_match = hostname hostname_for_match = hostname
hostname_for_match = hostname.split('@', 1)[-1].split(':', 1)[0] hostname_for_match = hostname_for_match.split('@', 1)[-1].split(':', 1)[0]
overrides = [] overrides = []
pat = re.compile(r'^([a-zA-Z0-9_]+)[ \t]*=') pat = re.compile(r'^([a-zA-Z0-9_]+)[ \t]*=')
for i, a in enumerate(found_extra_args): for i, a in enumerate(found_extra_args):
@ -617,7 +626,7 @@ def run_ssh(ssh_args: List[str], server_args: List[str], found_extra_args: Tuple
need_to_request_data = False need_to_request_data = False
with restore_terminal_state() as echo_on: with restore_terminal_state() as echo_on:
rcmd, replacements, shm_name = get_remote_command( rcmd, replacements, shm_name = get_remote_command(
remote_args, host_opts, hostname, hostname_for_match, uname, echo_on, request_data=need_to_request_data) remote_args, host_opts, hostname_for_match, uname, echo_on, request_data=need_to_request_data)
cmd += rcmd cmd += rcmd
try: try:
p = subprocess.Popen(cmd) p = subprocess.Popen(cmd)

View File

@ -1346,7 +1346,7 @@ class Boss:
# the system less before macOS 12.3 barfs up OSC codes, so sanitize them ourselves # the system less before macOS 12.3 barfs up OSC codes, so sanitize them ourselves
sentinel = os.path.join(cache_dir(), 'less-is-new-enough') sentinel = os.path.join(cache_dir(), 'less-is-new-enough')
if not os.path.exists(sentinel): if not os.path.exists(sentinel):
if less_version() >= 581: if less_version(cmd[0]) >= 581:
open(sentinel, 'w').close() open(sentinel, 'w').close()
else: else:
bdata = re.sub(br'\x1b\].*?\x1b\\', b'', bdata) bdata = re.sub(br'\x1b\].*?\x1b\\', b'', bdata)

View File

@ -41,7 +41,7 @@ class ScrollWindow(RemoteCommand):
pages = 'p' in amt pages = 'p' in amt
unscroll = 'u' in amt unscroll = 'u' in amt
mult = -1 if amt.endswith('-') and not unscroll else 1 mult = -1 if amt.endswith('-') and not unscroll else 1
q = int(amt.rstrip('+-pu')) q = int(amt.rstrip('+-plu'))
amount = q * mult, 'p' if pages else ('u' if unscroll else 'l') amount = q * mult, 'p' if pages else ('u' if unscroll else 'l')
return {'match': opts.match, 'amount': amount} return {'match': opts.match, 'amount': amount}

View File

@ -953,7 +953,7 @@ def macos_version() -> Tuple[int, ...]:
return tuple(map(int, platform.mac_ver()[0].split('.'))) return tuple(map(int, platform.mac_ver()[0].split('.')))
@run_once @lru_cache(maxsize=2)
def less_version(less_exe: str = 'less') -> int: def less_version(less_exe: str = 'less') -> int:
import subprocess import subprocess
o = subprocess.check_output([less_exe, '-V'], stderr=subprocess.STDOUT).decode() o = subprocess.check_output([less_exe, '-V'], stderr=subprocess.STDOUT).decode()

View File

@ -55,6 +55,7 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
t('ssh un@ip -i ident -p34', host='un@ip', port=34, identity_file='ident') t('ssh un@ip -i ident -p34', host='un@ip', port=34, identity_file='ident')
t('ssh un@ip -iident -p34', host='un@ip', port=34, identity_file='ident') t('ssh un@ip -iident -p34', host='un@ip', port=34, identity_file='ident')
t('ssh -p 33 main', port=33) t('ssh -p 33 main', port=33)
t('ssh -p 34 ssh://un@ip:33/', host='un@ip', port=34)
t('ssh --kitten=one -p 12 --kitten two -ix main', identity_file='x', port=12, extra_args=(('--kitten', 'one'), ('--kitten', 'two'))) t('ssh --kitten=one -p 12 --kitten two -ix main', identity_file='x', port=12, extra_args=(('--kitten', 'one'), ('--kitten', 'two')))
self.assertTrue(runtime_dir()) self.assertTrue(runtime_dir())

View File

@ -157,7 +157,7 @@ _ksi_main() {
# command like cd /test && cat. PS0 is evaluated before cd is run. # command like cd /test && cat. PS0 is evaluated before cd is run.
if [[ "${_ksi_prompt[last_reported_cwd]}" != "$PWD" ]]; then if [[ "${_ksi_prompt[last_reported_cwd]}" != "$PWD" ]]; then
_ksi_prompt[last_reported_cwd]="$PWD"; _ksi_prompt[last_reported_cwd]="$PWD";
builtin printf "\e]7;kitty-shell-cwd://%s%s\a" "$HOST" "$PWD" builtin printf "\e]7;kitty-shell-cwd://%s%s\a" "$HOSTNAME" "$PWD"
fi fi
fi fi
} }

View File

@ -15,7 +15,6 @@ mv_files_and_dirs() {
cd "$cwd" cd "$cwd"
} }
compile_terminfo() { compile_terminfo() {
tname=".terminfo" tname=".terminfo"
# Ensure the 78 dir is present # Ensure the 78 dir is present
@ -40,7 +39,6 @@ compile_terminfo() {
fi fi
} }
parse_passwd_record() { parse_passwd_record() {
printf "%s" "$(command grep -o '[^:]*$')" printf "%s" "$(command grep -o '[^:]*$')"
} }
@ -152,7 +150,7 @@ execute_sh_with_posix_env() {
command "$login_shell" -l -c ":" > /dev/null 2> /dev/null && return command "$login_shell" -l -c ":" > /dev/null 2> /dev/null && return
[ -z "$shell_integration_dir" ] && die "Could not read data over tty ssh kitten cannot function" [ -z "$shell_integration_dir" ] && die "Could not read data over tty ssh kitten cannot function"
sh_dir="$shell_integration_dir/sh" sh_dir="$shell_integration_dir/sh"
command mkdir -p "$sh_dir" || die "Creating $sh_dir failed" command mkdir -p "$sh_dir" || die "Creating directory $sh_dir failed"
sh_script="$sh_dir/login_shell_env.sh" sh_script="$sh_dir/login_shell_env.sh"
# Source /etc/profile, ~/.profile, and then check and source ENV # Source /etc/profile, ~/.profile, and then check and source ENV
printf "%s" ' printf "%s" '