kovidgoyal / kitty

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

[bug?] --cwd=current doesn't respect symlinks #7950

Closed mazunki closed 1 month ago

mazunki commented 1 month ago

Describe the bug Launching a new instance of kitty in the current working directory causes the new instance to dereference the symlink of the directory we were in.

To Reproduce Steps to reproduce the behavior:

  1. mkdir physical_dir
  2. ln -sT physical_dir relative_dir
  3. cd relative_dir
  4. kitty @ launch --cwd=current --type=os-window

After running pwd on the new instance I would expect cwd to be relative_dir and not physical_dir.

Screenshots image

We can see the newly spawned window on the right side, where I've run a single pwd command showing the unexpected path.

Environment details

kitty 0.36.4 created by Kovid Goyal
Linux mazpad 6.10.5-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 14 15:49:44 UTC 2024 x86_64
S
Kernel 6.10.5-200.fc40.x86_64 on an x86_64 (/dev/tty)

Running under: Wayland (sway version 1.9) missing: blur
OpenGL: '4.6 (Core Profile) Mesa 24.1.7' Detected version: 4.6
Frozen: False
Fonts:
  medium: NotoSansMono-Regular: /usr/share/fonts/google-noto-vf/NotoSansMono[wght].ttf:0
          Features: ()
    bold: NotoSansMono-Bold: /usr/share/fonts/google-noto-vf/NotoSansMono[wght].ttf:262144
          Features: ()
  italic: NotoSansMono-Regular: /usr/share/fonts/google-noto-vf/NotoSansMono[wght].ttf:0
          Features: ()
      bi: NotoSansMono-Bold: /usr/share/fonts/google-noto-vf/NotoSansMono[wght].ttf:262144
          Features: ()
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib64/kitty
  extensions dir: /usr/lib64/kitty/kitty
  system shell: /usr/bin/zsh
Loaded config files:
  /home/mazunki/.config/kitty/kitty.conf

Config options different from defaults:
allow_remote_control    yes
enable_audio_bell       False
font_family             FiraCode Nerd Font Mono
font_size               14.0
tab_bar_edge            1
tab_bar_margin_height   TabBarMarginHeight(outer=12.0, inner=6.0)
tab_bar_margin_width    6.0
tab_bar_min_tabs        1
tab_bar_style           custom
tab_separator           
tab_title_template       ({index}) {title.replace('~/.config', ' ').replace('~/.local/share', ' ').replace('~/', ' /').replace('~', '🏠')} 
window_margin_width     FloatEdges(left=8.0, top=4.0, right=8.0, bottom=8.0)
Added shortcuts:
    ctrl+f →  launch --type=overlay --stdin-source=@screen_scrollback fzf --no-sort --no-mouse --exact -i
    f1 →  show_first_command_output_on_screen
    super+d →  new_window
Changed shortcuts:
    kitty_mod+enter →  launch --cwd=current --copy-env --type=os-window
    kitty_mod+n →  launch --cwd=current --copy-env --type=window
    kitty_mod+t →  launch --cwd=current --copy-env --type=tab
Colors:
    active_border_color     #7287fd   
    active_tab_background   #8839ef   
    active_tab_foreground   #eff1f5   
    background              #eff1f5   
    bell_border_color       #df8e1d   
    color0                  #5c5f77   
    color1                  #d20f39   
    color10                 #40a02b   
    color11                 #df8e1d   
    color12                 #1e66f5   
    color13                 #ea76cb   
    color14                 #179299   
    color15                 #bcc0cc   
    color2                  #40a02b   
    color3                  #df8e1d   
    color4                  #1e66f5   
    color5                  #ea76cb   
    color6                  #179299   
    color7                  #acb0be   
    color8                  #6c6f85   
    color9                  #d20f39   
    cursor                  #dc8a78   
    cursor_text_color       #eff1f5   
    foreground              #4c4f69   
    inactive_border_color   #9ca0b0   
    inactive_tab_background #9ca0b0   
    inactive_tab_foreground #4c4f69   
    mark1_background        #7287fd   
    mark1_foreground        #eff1f5   
    mark2_background        #8839ef   
    mark2_foreground        #eff1f5   
    mark3_background        #209fb5   
    mark3_foreground        #eff1f5   
    selection_background    #dc8a78   
    selection_foreground    #eff1f5   
    tab_bar_background      #bcc0cc   
    url_color               #dc8a78   

Important environment variables seen by the kitty process:
    PATH                                /home/mazunki/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/mazunki/.local/src/shellscripts
    LANG                                en_US.UTF-8
    EDITOR                              /usr/bin/nano
    SHELL                               /usr/bin/zsh
    DISPLAY                             :0
    WAYLAND_DISPLAY                     wayland-1
    USER                                mazunki
    XCURSOR_SIZE                        24
    XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session1
    XDG_SEAT                            seat0
    XDG_SESSION_DESKTOP                 sway
    XDG_SESSION_TYPE                    wayland
    XDG_CURRENT_DESKTOP                 sway
    XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
    XDG_SESSION_CLASS                   user
    XDG_VTNR                            2
    XDG_SESSION_ID                      2
    XDG_RUNTIME_DIR                     /run/user/1997
    XDG_DATA_DIRS                       /usr/local/share:/usr/share:/home/mazunki/.nix-profile/share:/nix/var/nix/profiles/default/share

Additional context I have enabled remote control for the sake of the screenshot. Normally I use a mapping to open a new os window.

kovidgoyal commented 1 month ago

If that's the behavior you want use

--cwd=$(PWD) not --cwd=current

mazunki commented 1 month ago

If that's the behavior you want use

--cwd=$(PWD) not --cwd=current

Can I do this when setting my mappings? e.g

map kitty_mod+t launch --cwd=current --copy-env --type=tab
map kitty_mod+n launch --cwd=current --copy-env --type=window
map kitty_mod+enter launch --cwd=current --copy-env --type=os-window

I tried setting --cwd=$(PWD) and --cwd=${PWD} here, none of which seem to work.

kovidgoyal commented 1 month ago

Nope only with remote control, run from a shell

kovidgoyal commented 1 month ago

And I should note that while on Linux/BSD it is possible to use the symlink rather than the realpath it isnt on macos, the OS api returns real paths, and so for consistency it behaves the same on both platforms.

mazunki commented 1 month ago

for consistency it behaves the same on both platforms.

I see, that's a fair reason. Thanks. I suspect that means a PR to provide this would not be desired, either.

Any suggestions on how I could make do with this? (I parse my CWD as part of my shell to trigger some hooks, so the difference is meaningful on my end)

kovidgoyal commented 1 month ago

You can write your own kitten that does what you want, see https://sw.kovidgoyal.net/kitty/kittens/custom/

It can set cwd to os.readlink('/proc/{pid_of_foreground_process}/exe') and then pass the open request on to the usual kitty machinery.