Compare commits

...

4 Commits

Author SHA1 Message Date
Arti Zirk 32e4427466 Remove current != found venv activation
That allows activating non default venvs
2023-06-21 23:27:11 +03:00
Arti Zirk c9dff2f155 Use zsh extended glob magic to find python venvs 2023-06-21 21:00:25 +03:00
Arti Zirk 5d3b5af7ed Add support for showing custom pyvenv prompt 2023-06-21 21:00:25 +03:00
Arti Zirk b47f79401f Make new-scrach use local variables 2023-06-21 21:00:25 +03:00
1 changed files with 16 additions and 18 deletions

34
.zshrc
View File

@ -5,7 +5,13 @@ fpath=( ~/.config/zsh/functions $fpath)
# Virtualenv support
function _virtual_env_prompt () {
REPLY=${VIRTUAL_ENV+(${VIRTUAL_ENV:t}) }
# new pyvenv has a seperate variable for custom prompt value
REPLY=${VIRTUAL_ENV_PROMPT+${VIRTUAL_ENV_PROMPT}}
# support old-school virtualenv
if [[ -z "${REPLY}" ]]; then
REPLY=${VIRTUAL_ENV+(${VIRTUAL_ENV:t}) }
fi
}
grml_theme_add_token virtual-env -f _virtual_env_prompt '%F{magenta}' '%f'
@ -95,21 +101,13 @@ setopt cdable_vars
# Enable or disable python virtual env
function chpwd_auto_python_venv() {
local venv_dir
local cur_dir="${PWD}"
while [[ "${cur_dir}" != / ]]; do
if [[ -f "${cur_dir}/venv/bin/activate" ]]; then
venv_dir="${cur_dir}/venv"
break
fi
# :P does `realpath(3)`
# :h removes 1 trailing pathname component
cur_dir="${cur_dir:P:h}"
done
if [[ -z "${VIRTUAL_ENV}" ]] && [[ -n "${venv_dir}" ]]; then
# we found venv dir that is not yet activated
source "${venv_dir}"/bin/activate
elif [[ -z "${venv_dir}" ]] && [[ -n "${VIRTUAL_ENV}" ]]; then
local venv_activation_script=((../)#(.|)(v|)env/bin/activate(#qN.omY1:a))
# dont check for (current_venv != found_venv) here because
# we want to support swtiching between venvs
if [[ -n "${venv_activation_script}" && -z "${VIRTUAL_ENV}" ]]; then
# we found venv dir that is not yet activated or is different from currently active one
source "${venv_activation_script}"
elif [[ -z "${venv_activation_script}" && -n "${VIRTUAL_ENV}" ]]; then
# we have activated virtual env but we cant find venv folder anymore
deactivate
fi
@ -182,8 +180,8 @@ setopt pushdminus
# Utility functions
function new-scratch {
cur_dir="$HOME/scratch"
new_dir="$HOME/tmp/scratch-`date +'%s'`"
local cur_dir="$HOME/scratch"
local new_dir="$HOME/tmp/scratch-`date +'%s'`"
mkdir -p $new_dir
ln -nfs $new_dir $cur_dir
cd $cur_dir