kovidgoyal / kitty

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

Workaround for launching with `--copy-env` from binding? #7499

Closed ej-shafran closed 3 months ago

ej-shafran commented 3 months ago

Describe the bug

When launching using the launch command from a binding defined in the config, using --copy-env does not load variables which have been set by shell startup scripts and the like. For example, I would like to launch nvim by pressing kitty_mod+e, but doing this means the PATH environment variable is not updated with my modifications from my ~/.zshenv file (this doesn't happen if I run kitty @ launch --copy-env nvim from my shell).

I know this has been mentioned before (#2711) but I couldn't figure out a workaround from this mentioned issue. Right now my workaround is to do launch nvim +'lua vim.env.PATH = vim.fn.system("env | grep PATH")' - note that I can't do launch nvim +'let $PATH = system("echo $PATH") because $PATH is replaced in the keybinding itself by Kitty which means the out-of-sync value is used...

Basically: is there some way to launch from a binding while dynamically loading environment variables? Or at least, running the shell startup files? If not, is there some way to define a launch binding without expanding environment variables?

To Reproduce Steps to reproduce the behavior:

  1. Add map kitty_mod+e launch --copy-env nvim (or use something other than nvim if you don't have it) to your config file
  2. Add export PATH="$PATH:/some/other/directory" to your ~/.zshenv file
  3. Re-source your config file
  4. kitty_mod+e
  5. :echo $PATH
  6. See that result is different from :!echo $PATH

Environment details

Details

``` kitty 0.35.1 (1bfb1de7fc) created by Kovid Goyal Darwin macbook-pro-4.lan 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:05 PDT 2024; root:xnu-10063.101.17~1/RELEASE_X86_64 x86_64 ProductName: macOS ProductVersion: 14.4.1 BuildVersion: 23E224 OpenGL: '4.1 INTEL-18.8.4' Detected version: 4.1 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: /bin/zsh Loaded config files: /Users/ejshafran/.config/kitty/kitty.conf Config options different from defaults: active_tab_font_style (True, False) allow_remote_control yes enable_audio_bell False enabled_layouts ['splits:split_axis=vertical', 'stack'] font_family FiraCode font_size 12.0 hide_window_decorations 1 inactive_tab_font_style (True, False) kitty_mod cmd listen_on unix:/tmp/mykitty macos_option_as_alt 3 macos_titlebar_color 370548226 selection_foreground None shell_integration frozenset({'no-cursor'}) tab_fade (1.0,) window_padding_width FloatEdges(left=8.0, top=8.0, right=8.0, bottom=8.0) Added shortcuts: ctrl+h → pass_keys left ctrl+h ctrl+j → pass_keys bottom ctrl+j ctrl+k → pass_keys top ctrl+k ctrl+l → pass_keys right ctrl+l ctrl+shift+c → copy_to_clipboard ctrl+shift+v → paste_from_clipboard kitty_mod+d → launch --location=vsplit --cwd=current kitty_mod+shift+r → debug_config Removed shortcuts: cmd++ → change_font_size all +2.0 cmd+, → edit_config_file cmd+- → change_font_size all -2.0 cmd+0 → change_font_size all 0 cmd+1 → first_window cmd+2 → second_window cmd+3 → third_window cmd+4 → fourth_window cmd+5 → fifth_window cmd+6 → sixth_window cmd+7 → seventh_window cmd+8 → eighth_window cmd+9 → ninth_window cmd+= → change_font_size all +2.0 cmd+c → copy_to_clipboard cmd+down → scroll_line_down cmd+end → scroll_end cmd+enter → new_window cmd+h → hide_macos_app cmd+home → scroll_home cmd+k → clear_terminal to_cursor active cmd+m → minimize_macos_window cmd+n → new_os_window cmd+page_down → scroll_page_down cmd+page_up → scroll_page_up cmd+q → quit cmd+r → start_resizing_window cmd+t → new_tab cmd+up → scroll_line_up cmd+v → paste_from_clipboard cmd+w → close_tab ctrl+cmd+, → load_config_file ctrl+cmd+f → toggle_fullscreen kitty_mod+enter → new_window kitty_mod+q → close_tab kitty_mod+w → close_window opt+cmd+h → hide_macos_other_apps opt+cmd+r → clear_terminal reset active opt+cmd+s → toggle_macos_secure_keyboard_entry shift+cmd+[ → previous_tab shift+cmd+] → next_tab shift+cmd+w → close_os_window Changed shortcuts: kitty_mod+, → set_tab_title kitty_mod+0 → change_font_size all 0 kitty_mod+1 → goto_tab 1 kitty_mod+2 → goto_tab 2 kitty_mod+3 → goto_tab 3 kitty_mod+4 → goto_tab 4 kitty_mod+5 → goto_tab 5 kitty_mod+6 → goto_tab 6 kitty_mod+7 → goto_tab 7 kitty_mod+8 → goto_tab 8 kitty_mod+9 → goto_tab 9 kitty_mod+[ → kitty_scrollback_nvim kitty_mod+] → kitty_scrollback_nvim --config ksb_builtin_last_cmd_output kitty_mod+b → move_tab_backward kitty_mod+e → launch --cwd=current --type=overlay nvim +'lua vim.env.PATH = vim.fn.system("env | grep PATH")' kitty_mod+f → move_tab_forward kitty_mod+h → open_hint --type hyperlink, open_hint --type linenum, open_hint --type hash --program -, open_hint --type word --program -, open_hint --type line --program -, open_hint --type path --program "launch --copy-env --type=overlay nvim", open_hint --type path --program -, hide_macos_app kitty_mod+k → send_key ctrl+l kitty_mod+n → next_tab kitty_mod+p > f → previous_tab, kitten hints --type hyperlink, kitten hints --type linenum, kitten hints --type hash --program -, kitten hints --type word --program -, kitten hints --type line --program -, kitten hints --type path, kitten hints --type path --program - kitty_mod+r → load_config_file kitty_mod+t → new_tab_with_cwd kitty_mod+z → toggle_layout stack shift+cmd+/ → show_kitty_doc overview shift+cmd+d → launch --location=hsplit --cwd=current Colors: active_border_color #3d59a1 active_tab_background #16161e active_tab_foreground #3d59a1 background #1a1b26 bell_border_color #e0af68 color0 #414868 color1 #f7768e color10 #73daca color11 #e0af68 color12 #7aa2f7 color13 #bb9af7 color14 #7dcfff color15 #c0caf5 color2 #73daca color3 #e0af68 color4 #7aa2f7 color5 #bb9af7 color6 #7dcfff color7 #c0caf5 color8 #414868 color9 #f7768e cursor #c0caf5 cursor_text_color #1a1b26 foreground #a9b1d6 inactive_border_color #101014 inactive_tab_background #16161e inactive_tab_foreground #787c99 selection_background #28344a tab_bar_background #101014 url_color #9ece6a Important environment variables seen by the kitty process: PATH /Applications/kitty.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin LANG en_US.UTF-8 SHELL /bin/zsh USER ejshafran ```

Additional context This is a problem with the kitty configuration so I think --config NONE doesn't make sense here, but I can try to come up with something if you think it's needed...

kovidgoyal commented 3 months ago

The docs for --copy-env tell you the available alternatives. https://sw.kovidgoyal.net/kitty/launch/#cmdoption-launch-copy-env

And if you want to do it via a binding, I suggest creating a binding in your shell to run one of those commands.

kovidgoyal commented 3 months ago

Oh and since you seem to want to read env vars from shell startup scripts, either set those env vars globally instead or use

launch zsh -il "exec nvim"

ej-shafran commented 3 months ago

Oh and since you seem to want to read env vars from shell startup scripts, either set those env vars globally instead or use

launch zsh -il "exec nvim"

Thanks!

Noting that it should be launch zsh -il -c "exec nvim" if anyone comes across this