Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kitty +kitten ssh inputs commands in shell #5227

Closed
phgz opened this issue Jun 23, 2022 · 5 comments
Closed

kitty +kitten ssh inputs commands in shell #5227

phgz opened this issue Jun 23, 2022 · 5 comments
Labels

Comments

@phgz
Copy link

phgz commented Jun 23, 2022

Describe the bug
When I use kitty +kitten ssh, I get a gibberish of characters being input on the remote shell.

To Reproduce
Steps to reproduce the behavior:

  1. kitty +kitten ssh <server>;
  2. See screenshot.

Screenshots
screenstart
screenend

Environment details

kitty 0.25.2 created by Kovid Goyal
Darwin <private> 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64
ProductName:	macOS ProductVersion:	12.3.1 BuildVersion:	21E258
Frozen: True
Paths:
  kitty: /Applications/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions
  system shell: /opt/homebrew/bin/fish
Loaded config files:
  /Users/pg/.config/kitty/kitty.conf

Config options different from defaults:
clipboard_control                  ('write-clipboard', 'write-primary', 'read-clipboard', 'read-primary', 'no-append')
cursor_blink_interval              0.0
cursor_text_color                  None
font_family                        FantasqueSansMono Nerd Font
font_size                          19.0
macos_option_as_alt                2
macos_quit_when_last_window_closed True
macos_thicken_font                 0.25
shell_integration                  frozenset({'disabled'})
Colors:
	active_border_color                #e1e4e8   
	active_tab_background              #0366d6   
	active_tab_foreground              #f6f8fa   
	background                         #f4f4f4   
	color0                             #24292e   
	color1                             #d73a49   
	color10                            #22863a   
	color11                            #b08800   
	color12                            #005cc5   
	color13                            #5a32a3   
	color14                            #3192aa   
	color15                            #d1d5da   
	color16                            #b08800   
	color17                            #cb2431   
	color2                             #28a745   
	color3                             #dbab09   
	color4                             #0366d6   
	color5                             #5a32a3   
	color6                             #0598bc   
	color7                             #6a737d   
	color8                             #959da5   
	color9                             #cb2431   
	cursor                             #044289   
	foreground                         #24292f   
	inactive_border_color              #e1e4e8   
	inactive_tab_background            #666666   
	inactive_tab_foreground            #f6f8fa   
	selection_background               #dbe9f9   
	selection_foreground               #24292f   
	url_color                          #24292f   

Important environment variables seen by the kitty process:
	PATH                                /Applications/kitty.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin
	LANG                                fr_CA.UTF-8
	SHELL                               /opt/homebrew/bin/fish
	USER                                pg

Additional context
When ran with kitty --config NONE, I get the following logs:

kitty --config NONE
[174 19:40:51.167097] WARNING: Your system's OpenGL implementation does not have glCopyImageSubData, falling back to a slower implementation
[174 19:40:51.198625] [PARSE ERROR] The application is trying to use xterm's modifyOtherKeys. This is superseded by the kitty keyboard protocol: https://sw.kovidgoyal.net/kitty/keyboard-protocol/ the application should be updated to use that
[174 19:40:51.198659] Application escape mode is not supported, the extended keyboard protocol should be used instead
[174 19:40:51.198664] [PARSE ERROR] The application is trying to use xterm's modifyOtherKeys. This is superseded by the kitty keyboard protocol: https://sw.kovidgoyal.net/kitty/keyboard-protocol/ the application should be updated to use that
[174 19:40:51.198668] Application escape mode is not supported, the extended keyboard protocol should be used instead

I use fish shell 3.5.0 and here is the minimal config to reproduce the bug.

function tmux_attach
    tmux has-session -t remote
    and tmux attach-session -t remote
end

function tmux_new_session
    tmux new-session -s remote
end

function initialize_tmux
    set PPID (ps -p %self -o ppid="" | xargs)

    if ps -p $PPID | grep -q ssh
        tmux_attach
        or tmux_new_session
        and kill -15 %self
        or echo "tmux failed to start; using plain fish shell"
    end
end

test -t 0 && initialize_tmux

I use TMUX 3.3a and the error can be reproduced with an empty tmux.conf.

I tried running the same script with kitty 0.24.4 and everything is fine. The logs now only contain:

[174 20:27:26.251211] WARNING: Your system's OpenGL implementation does not have glCopyImageSubData, falling back to a slower implementation
[174 20:27:26.267660] Application escape mode is not supported, the extended keyboard protocol should be used instead
[174 20:27:26.267704] Application escape mode is not supported, the extended keyboard protocol should be used instead
@phgz phgz added the bug label Jun 23, 2022
@page-down
Copy link
Contributor

The new version of ssh kitten does not support use in tmux.
The latest implementation uses a more efficient way to transfer data directly via TTY.
Any type of wrapper will affect this.

@kovidgoyal
Copy link
Owner

Yeah tmux, the great breaker of everything :) The problem is that in
the new design the ssh kitten sends an escape code to kitty before even
running ssh and kitty writes escape codes back to the TTY with the data,
this allows for instant start without a roundtrip delay, but if tmux is
in the way, then it intercepts and breaks this communication. I dont
know of a good way to fix it, sorry.

@phgz
Copy link
Author

phgz commented Jun 24, 2022

Thanks anyway. I will try to knock at TMUX's door since with kitty 0.25.2 and TMUX 3.2a there is no problem. Maybe they can do something on their side :)

@kovidgoyal
Copy link
Owner

Actually, it might be possible to use tmux passthrough escape codes. Will have to investigate if I can find the time. It will only work if you use the ssh kitten in the currently active tmux pane, but that is the common case.

@kovidgoyal kovidgoyal reopened this Jun 29, 2022
Gelio added a commit to Gelio/ubuntu-dotfiles that referenced this issue Oct 21, 2022
The version of tmux in the Ubuntu 20.04 LTS is tmux 3.0, which is
outdated. The latest version of tmux at the time of writing is 3.3a.

Using the latest version fixes a problem with using kitty's SSH kitten
in tmux [0].

[0]: kovidgoyal/kitty#5227
@eliliam
Copy link

eliliam commented Jun 27, 2023

I think I found the fix for this, after a fair bit of experimentation, I found that adding the following line to my tmux.conf file solved the issue of using kitty +kitten ssh myserver from within a tmux pane.

set -g allow-passthrough on

Let me know if this solves it for anyone else. I was digging around the source code and noticed that if I manually set the KITTY_PID env var to the correct PID that it was set to before starting tmux then ssh worked just fine. After more digging through previous commits in the source code I found the following line which was the key to solving this issue:

cp = subprocess.run([tmux, 'set', '-p', 'allow-passthrough', 'on'])

While this file no longer contains this detail on the latest commits, I think I found the equivalent code in the current source as well:

c, stderr = tmux_command("set", "-p", "allow-passthrough", "on")

Edit:
The reason my change is using set -g instead of set -p is so that tmux globally sets this across all sessions, windows, and panes, instead of just the current pane. I am not fully aware of the implications of this, however I personally have not had any issues thus far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants