kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
23.71k stars 956 forks source link

`kitten ssh` does not update `PATH` for fish shell on OpenBSD host #7605

Closed nalzok closed 2 months ago

nalzok commented 2 months ago

Describe the bug kitten ssh does not update PATH for fish shell on OpenBSD host

To Reproduce

~ $ kitty +kitten ssh sentinel
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

qys@sentinel ~> echo $PATH
/home/qys/.local/bin /usr/local/bin /usr/bin /bin

qys@sentinel ~> ls /home/qys/.local/share/kitty-ssh-kitten
kitty/             shell-integration/

qys@sentinel ~> uname -a
OpenBSD sentinel.lan 7.5 GENERIC.MP#82 amd64

qys@sentinel ~> which kitten
which: kitten: Command not found.

Screenshots

image

Environment details

kitty 0.35.1 created by Kovid Goyal
Darwin Qingyaos-MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Apr 24 06:02:02 PDT 2024; root:xnu-8020.240.18.708.4~1/RELEASE_X86_64 x86_64
ProductName:    macOS ProductVersion:   12.7.5 BuildVersion:    21H1222
OpenGL: '4.1 INTEL-18.8.16' Detected version: 4.1
Frozen: False
Paths:
  kitty: /Applications/MacPorts/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/MacPorts/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/MacPorts/kitty.app/Contents/Resources/kitty/kitty
  system shell: /opt/local/bin/fish
Loaded config files:
  /Users/qys/.config/kitty/kitty.conf

Config options different from defaults:
cursor_blink_interval              0.0
enable_audio_bell                  False
font_family                        PragmataPro Mono
font_features:
{'PragmataProMono-Regular': ('+calt', '+cv03')}
font_size                          18.0
macos_quit_when_last_window_closed True
shell_integration                  frozenset({'no-cursor'})
tab_bar_edge                       1
tab_bar_style                      separator
tab_title_template                 {fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{sup.index}{title}
visual_bell_duration               0.1
Changed mouse actions:
    right press ungrabbed →  mouse_select_command_output
Removed shortcuts:
    cmd+, →  edit_config_file
    cmd+enter →  new_window
    cmd+h →  hide_macos_app
    cmd+k →  clear_terminal to_cursor active
    cmd+m →  minimize_macos_window
    cmd+n →  new_os_window
    cmd+q →  quit
    cmd+t →  new_tab
    cmd+w →  close_tab
    ctrl+cmd+, →  load_config_file
    ctrl+cmd+f →  toggle_fullscreen
    opt+cmd+h →  hide_macos_other_apps
    opt+cmd+r →  clear_terminal reset active
    opt+cmd+s →  toggle_macos_secure_keyboard_entry
    shift+cmd+/ →  open_url https://sw.kovidgoyal.net/kitty/
    shift+cmd+[ →  previous_tab
    shift+cmd+] →  next_tab
    shift+cmd+d →  close_window
    shift+cmd+w →  close_os_window
Changed shortcuts:
    cmd+0 →  goto_tab    10
    cmd+1 →  goto_tab    1
    cmd+2 →  goto_tab    2
    cmd+3 →  goto_tab    3
    cmd+4 →  goto_tab    4
    cmd+5 →  goto_tab    5
    cmd+6 →  goto_tab    6
    cmd+7 →  goto_tab    7
    cmd+8 →  goto_tab    8
    cmd+9 →  goto_tab    9

Important environment variables seen by the kitty process:
    PATH                                /Applications/MacPorts/kitty.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin
    LANG                                en_US.UTF-8
    SHELL                               /opt/local/bin/fish
    DISPLAY                             /private/tmp/com.apple.launchd.VQEfQr9siC/org.xquartz:0
    USER                                qys
    LC_CTYPE                            UTF-8

Additional context

I'm attaching my config file below, but this bug can be reproduced by kitty --config NONE. I'm using fish, version 3.7.1 on the macOS client and fish, version 3.7.0 on the OpenBSD host.

font_family                         PragmataPro Mono
bold_font                           auto
italic_font                         auto
bold_italic_font                    auto
font_size                           18.0
font_features                       PragmataProMono-Regular +calt +cv03

cursor_blink_interval               0

mouse_map                           right press ungrabbed mouse_select_command_output

enable_audio_bell                   no
visual_bell_duration                0.1

tab_bar_edge                        top
tab_bar_style                       separator
tab_title_template                  "{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{sup.index}{title}"

shell_integration                   no-cursor

macos_quit_when_last_window_closed  yes

map                                 cmd+1   goto_tab    1
map                                 cmd+2   goto_tab    2
map                                 cmd+3   goto_tab    3
map                                 cmd+4   goto_tab    4
map                                 cmd+5   goto_tab    5
map                                 cmd+6   goto_tab    6
map                                 cmd+7   goto_tab    7
map                                 cmd+8   goto_tab    8
map                                 cmd+9   goto_tab    9
map                                 cmd+0   goto_tab    10
nalzok commented 2 months ago

After I messed around a little bit, kitten ssh updates PATH now, but in the wrong way. For example, here is the PATH when I SSH with /usr/bin/ssh

~ $ command ssh sentinel
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

qys@sentinel ~> echo $PATH
/home/qys/.local/bin /usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin

qys@sentinel ~> doas pkg_add -u
doas (qys@sentinel.lan) password: 
quirks-7.14 signed on 2024-07-03T17:56:08Z

However, if I use kitten ssh, stuff like /usr/sbin is no longer present in PATH

~ $ kitty +kitten ssh sentinel
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

qys@sentinel ~> echo $PATH
/home/qys/.local/bin /usr/local/bin /usr/bin /bin /home/qys/.local/share/kitty-ssh-kitten/kitty/bin

qys@sentinel ~> doas pkg_add -u
doas (qys@sentinel.lan) password: 
doas: pkg_add: command not found

Of course, I can manually add /usr/sbin back to PATH as a workaround, but this seems like a bug in kitty's shell integration: it's probably not intentional to have kitty remove directories in PATH.

kovidgoyal commented 2 months ago

The ssh kitten does not update PATH that will be done presumably by your shell's rc files. And you have setup your shell's rc files to not update path on non-interactive invocations. Fix that and you will be fine.

nalzok commented 2 months ago

Sorry, I'm not sure what is the fix. Here is the ~/.config/fish/config.fish on the remote OpenBSD host,

set -px PATH $HOME/.local/bin

if status is-interactive
    # Commands to run in interactive sessions can go here
    alias vi='/usr/local/bin/nvim'
    set -gx EDITOR /usr/local/bin/nvim
end

if test $TERM = "xterm-kitty";
    alias ssh="kitty +kitten ssh"
end

As you can see, I did not set up my shell's rc files to not update path on non-interactive invocations. In fact, the problem persists even with an empty ~/.config/fish/config.fish.

What should I put into ~/.config/fish/config.fish?

kovidgoyal commented 2 months ago

This will likely be the system wide rc files not the user ones. Whatever on your system is responsible for adding /usr/sbin and friends to path.

nalzok commented 1 month ago

Thanks. For posterity's sake, I fixed the issue by executing the following command:

fish_add_path /usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin

It's still unclear to me who added /usr/sbin and friends to PATH, but everything works fine now:

$ set --show fish_user_paths
$fish_user_paths: set in universal scope, unexported, with 7 elements
$fish_user_paths[1]: |/usr/bin|
$fish_user_paths[2]: |/bin|
$fish_user_paths[3]: |/usr/sbin|
$fish_user_paths[4]: |/sbin|
$fish_user_paths[5]: |/usr/X11R6/bin|
$fish_user_paths[6]: |/usr/local/bin|
$fish_user_paths[7]: |/usr/local/sbin|

$ set --show PATH
$PATH: set in global scope, exported, a path variable with 8 elements
$PATH[1]: |/usr/bin|
$PATH[2]: |/bin|
$PATH[3]: |/usr/sbin|
$PATH[4]: |/sbin|
$PATH[5]: |/usr/X11R6/bin|
$PATH[6]: |/usr/local/bin|
$PATH[7]: |/usr/local/sbin|
$PATH[8]: |/home/qys/.local/share/kitty-ssh-kitten/kitty/bin|
$PATH: originally inherited as |/usr/local/bin:/usr/bin:/bin:/home/qys/.local/share/kitty-ssh-kitten/kitty/bin|