Implement venv detection for fish

This commit is contained in:
Kovid Goyal 2022-04-16 14:45:02 +05:30
parent 1daf745d74
commit 831043b773
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 28 additions and 6 deletions

View File

@ -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':

View File

@ -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"