kovidgoyal / kitty

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

Unable to open launch with --cwd=current when using custom session file and launch script is used #7537

Closed braindotai closed 5 months ago

braindotai commented 5 months ago

Describe the bug

I am not sure if its necessarily a bug but not a expected behavior as per my understanding. So I am trying to integrate distrobox shell inside kitty. I got to know about kitty session file that allows you to open kitty terminal in specific layout. With that custom session file, I also wanted to edit my kitty.conf so that on pressing ctrl+shift+enter ... the split panel runs the shell as per the current shell. If my current shell is host shell then ctrl+shift+enter should open host shell on current directory. But if I am inside distrobox and I press ctrl+shift+enter then it should open distrobox shell with the current directory.

Everything is working fine except one thing, on the very first run once I open Kitty - if I press ctrl+shift+enter "for the first time" being inside distrobox shell, new split happens with the distrobox shell (which is expected) but the directory where I am at is the home directory. Whereas if I press ctrl+shift+enter again, then everything is working fine and I am inside distrobox shell again located at correct "current" directory.

To Reproduce Steps to reproduce the behavior:

  1. My session.conf file:

    new_tab Workspace
    launch --env DISTRO_BOX_SHELL=arch-box distrobox enter arch-box

    Assigning DISTRO_BOX_SHELL env to help kitty decide which shell to enter later

  2. My custom executable shell script launch_shell.sh which runs on launch to decide whether to enter distrobox shell or not

    
    #!/bin/bash

if [ "$DISTRO_BOX_SHELL" = "arch-box" ]; then distrobox enter arch-box else zsh fi

And my `kitty.conf`

map kitty_mod+enter launch --cwd=current --copy-env


**Screenshots**
![image](https://github.com/kovidgoyal/kitty/assets/50226064/200082c6-cd91-4c6f-be13-4f4577b12b7a)

**Environment details**

kitty 0.35.1 created by Kovid Goyal Linux archtuf 6.9.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 31 May 2024 15:14:45 +0000 x86_64 Arch Linux 6.9.3-arch1-1 (/dev/tty)

Running under: X11 OpenGL: '4.6 (Core Profile) Mesa 24.1.1-arch1.1' Detected version: 4.6 Frozen: False Paths: kitty: /usr/bin/kitty base dir: /usr/lib/kitty extensions dir: /usr/lib/kitty/kitty system shell: /usr/bin/zsh Loaded config files: /home//.config/kitty/kitty.conf

Config options different from defaults: background_image_layout scaled background_opacity 0.7 background_tint 0.9 copy_on_select clipboard dynamic_background_opacity True enabled_layouts ['grid'] font_family JetBrains Mono hide_window_decorations 1 modify_font: baseline 0 cell_height 0 cell_width 100% shell_integration frozenset({'no-cursor'}) tab_bar_style powerline tab_powerline_style slanted term xterm-256color window_padding_width FloatEdges(left=4.0, top=4.0, right=4.0, bottom=4.0) Added shortcuts: ctrl+alt+n → set_tab_title ctrl+down → neighboring_window down ctrl+home → resize_window reset ctrl+left → neighboring_window left ctrl+right → neighboring_window right ctrl+up → neighboring_window up shift+down → move_window down shift+left → move_window left shift+right → move_window right shift+up → move_window up Changed shortcuts: kitty_mod+down → resize_window shorter 3 kitty_mod+enter → launch --cwd=current --copy-env ~/Desktop/GitHub/braindotdev/kitty/config/launch_shell.sh kitty_mod+left → resize_window narrower kitty_mod+right → resize_window wider kitty_mod+t → new_tab_with_cwd kitty_mod+up → resize_window taller Colors: color1 #c6c678
color10 #ffe34d
color11 #ffff00
color12 #ffffff
color13 #ae8d20
color14 #ffff99
color2 #ffe34d
color3 #ffff00
color4 #f1ff24
color5 #ae8d20
color6 #ffff99
color7 #ffffff
color8 #7f6f21
color9 #ffffff
cursor #ffe34d
foreground #ffffff
selection_background #ffffff

Important environment variables seen by the kitty process: PATH /usr/local/bin:/usr/bin:/usr/local/sbin:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin:/var/lib/flatpak/exports/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl LANG en_US.UTF-8 SHELL /usr/bin/zsh DISPLAY :1 USER XDG_DATA_DIRS /home//.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/ XDG_RUNTIME_DIR /run/user/1000 XDG_CURRENT_DESKTOP GNOME XDG_MENU_PREFIX gnome- XDG_SESSION_CLASS user XDG_SESSION_DESKTOP gnome XDG_SESSION_TYPE x11


**Additional context**
I am launching kitty like this:

kitty --start-as=maximized --session=


Thanks for your time.
kovidgoyal commented 5 months ago

I don't know what distrobox is. Some kind of container system? I don't really understand how your solution is supposed to work. launch --cwd=current will launch whatever the process is with its current directory set to some path inside the container. That path may or may not exist on the host and may or may not be accessible on the host.

To do what you want to do would require writing a kitten that wraps the launch command. It can inspect the active window, see if its in the container, if so extract the path to the cwd in the container and then run a new window connected to the container at the cwd.