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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue