From 831043b773ebceb0e53b9b9ead72db96ed8d82f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Apr 2022 14:45:02 +0530 Subject: [PATCH] Implement venv detection for fish --- kitty/launch.py | 10 ++++---- .../kitty-shell-integration.fish | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/kitty/launch.py b/kitty/launch.py index ca46be163..06d588c31 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -569,16 +569,14 @@ class CloneCmd: if k == 'a': self.args.append(v) elif k == 'env': - self.env = parse_bash_env(v) if self.envfmt == 'bash' else parse_null_env(v) - for filtered in ( + env = parse_bash_env(v) if self.envfmt == 'bash' else parse_null_env(v) + self.env = {k: v for k, v in env.items() if k not in ( 'HOME', 'LOGNAME', 'USER', - # some people export these. We want the shell rc files to - # recreate them + # some people export these. We want the shell rc files to recreate them 'PS0', 'PS1', 'PS2', 'PS3', 'PS4', 'RPS1', 'PROMPT_COMMAND', 'SHLVL', # skip SSH environment variables 'SSH_CLIENT', 'SSH_CONNECTION', 'SSH_ORIGINAL_COMMAND', 'SSH_TTY', 'SSH2_TTY', - ): - self.env.pop(filtered, None) + )} elif k == 'cwd': self.cwd = v elif k == 'argv': diff --git a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish index 71234d8bd..45d8bbb4e 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -24,6 +24,14 @@ not functions -q __ksi_schedule || exit 0 set -q fish_killring || set -q status_generation || string match -qnv "3.1.*" "$version" or echo -en \eP@kitty-print\|V2FybmluZzogVXBkYXRlIGZpc2ggdG8gdmVyc2lvbiAzLjMuMCsgdG8gZW5hYmxlIGtpdHR5IHNoZWxsIGludGVncmF0aW9uLgo=\e\\ && exit 0 || exit 0 +if test -n "$KITTY_IS_CLONE_LAUNCH" + set -g __ksi_is_clone_launch "$KITTY_IS_CLONE_LAUNCH" + set --erase KITTY_IS_CLONE_LAUNCH + set -g __ksi_pre_rc_path "$PATH" + set -g __ksi_pre_rc_conda_default_env "$CONDA_DEFAULT_ENV" + set -g __ksi_pre_rc_python_venv "$VIRTUAL_ENV" +end + function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after other scripts have run, we hope" functions --erase __ksi_schedule test -n "$KITTY_SHELL_INTEGRATION" || return 0 @@ -106,6 +114,22 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after end __update_cwd_osc end + + # Handle clone launches + if test -n "$__ksi_is_clone_launch" + set -gx --path PATH "$__ksi_pre_rc_path" + if test -n "$__ksi_pre_rc_python_venv" -a -r "$__ksi_pre_rc_python_venv/bin/activate.fish" + set -e VIRTUAL_ENV _OLD_FISH_PROMPT_OVERRIDE # activate.fish stupidly exports _OLD_FISH_PROMPT_OVERRIDE + source "$__ksi_pre_rc_python_venv/bin/activate.fish" + else if test -n "$__ksi_pre_rc_conda_default_env" + and type -q conda + and test "$__ksi_pre_rc_conda_default_env" != "$CONDA_DEFAULT_ENV" + echo $__ksi_pre_rc_conda_default_env + # for some reason that I cant be bothered to figure out this doesnt take effect + conda activate $_ksi_pre_rc_conda_default_env + end + set --erase __ksi_is_clone_launch __ksi_pre_rc_path __ksi_pre_rc_conda_default_env __ksi_pre_rc_python_venv + end end function clone-in-kitty -d "Clone the current fish session into a new kitty window"