mirror of https://github.com/artizirk/dotfiles.git
Compare commits
4 Commits
d3035549a5
...
32e4427466
Author | SHA1 | Date |
---|---|---|
Arti Zirk | 32e4427466 | |
Arti Zirk | c9dff2f155 | |
Arti Zirk | 5d3b5af7ed | |
Arti Zirk | b47f79401f |
34
.zshrc
34
.zshrc
|
@ -5,7 +5,13 @@ fpath=( ~/.config/zsh/functions $fpath)
|
||||||
|
|
||||||
# Virtualenv support
|
# Virtualenv support
|
||||||
function _virtual_env_prompt () {
|
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'
|
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
|
# Enable or disable python virtual env
|
||||||
function chpwd_auto_python_venv() {
|
function chpwd_auto_python_venv() {
|
||||||
local venv_dir
|
local venv_activation_script=((../)#(.|)(v|)env/bin/activate(#qN.omY1:a))
|
||||||
local cur_dir="${PWD}"
|
# dont check for (current_venv != found_venv) here because
|
||||||
while [[ "${cur_dir}" != / ]]; do
|
# we want to support swtiching between venvs
|
||||||
if [[ -f "${cur_dir}/venv/bin/activate" ]]; then
|
if [[ -n "${venv_activation_script}" && -z "${VIRTUAL_ENV}" ]]; then
|
||||||
venv_dir="${cur_dir}/venv"
|
# we found venv dir that is not yet activated or is different from currently active one
|
||||||
break
|
source "${venv_activation_script}"
|
||||||
fi
|
elif [[ -z "${venv_activation_script}" && -n "${VIRTUAL_ENV}" ]]; then
|
||||||
# :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
|
|
||||||
# we have activated virtual env but we cant find venv folder anymore
|
# we have activated virtual env but we cant find venv folder anymore
|
||||||
deactivate
|
deactivate
|
||||||
fi
|
fi
|
||||||
|
@ -182,8 +180,8 @@ setopt pushdminus
|
||||||
# Utility functions
|
# Utility functions
|
||||||
|
|
||||||
function new-scratch {
|
function new-scratch {
|
||||||
cur_dir="$HOME/scratch"
|
local cur_dir="$HOME/scratch"
|
||||||
new_dir="$HOME/tmp/scratch-`date +'%s'`"
|
local new_dir="$HOME/tmp/scratch-`date +'%s'`"
|
||||||
mkdir -p $new_dir
|
mkdir -p $new_dir
|
||||||
ln -nfs $new_dir $cur_dir
|
ln -nfs $new_dir $cur_dir
|
||||||
cd $cur_dir
|
cd $cur_dir
|
||||||
|
|
Loading…
Reference in New Issue