Commit 3b6a695b authored by Ashley Valent's avatar Ashley Valent
Browse files

Merge branch 'master' of github.com:avalent/oh-my-zsh

parents 3ba10ad0 ef7e53a7
# Push and pop directories on directory stack
alias pu='pushd'
alias po='popd'
# Basic directory operations
alias ...='cd ../..'
alias -- -='cd -'
# Super user
alias _='sudo'
alias please='sudo'
#alias g='grep -in'
# Show history
if [ "$HIST_STAMPS" = "mm/dd/yyyy" ]
then
alias history='fc -fl 1'
elif [ "$HIST_STAMPS" = "dd.mm.yyyy" ]
then
alias history='fc -El 1'
elif [ "$HIST_STAMPS" = "yyyy-mm-dd" ]
then
alias history='fc -il 1'
else
alias history='fc -l 1'
fi
# List direcory contents
alias lsa='ls -lah'
alias l='ls -lah'
alias ll='ls -lh'
alias la='ls -lAh'
alias afind='ack-grep -il'
...@@ -3,12 +3,10 @@ setopt auto_pushd ...@@ -3,12 +3,10 @@ setopt auto_pushd
setopt pushd_ignore_dups setopt pushd_ignore_dups
setopt pushdminus setopt pushdminus
alias ..='cd ..' alias -g ...='../..'
alias cd..='cd ..' alias -g ....='../../..'
alias cd...='cd ../..' alias -g .....='../../../..'
alias cd....='cd ../../..' alias -g ......='../../../../..'
alias cd.....='cd ../../../..'
alias cd/='cd /'
alias 1='cd -' alias 1='cd -'
alias 2='cd -2' alias 2='cd -2'
...@@ -20,23 +18,16 @@ alias 7='cd -7' ...@@ -20,23 +18,16 @@ alias 7='cd -7'
alias 8='cd -8' alias 8='cd -8'
alias 9='cd -9' alias 9='cd -9'
cd () {
if [[ "x$*" == "x..." ]]; then
cd ../..
elif [[ "x$*" == "x...." ]]; then
cd ../../..
elif [[ "x$*" == "x....." ]]; then
cd ../../../..
elif [[ "x$*" == "x......" ]]; then
cd ../../../../..
elif [ -d ~/.autoenv ]; then
source ~/.autoenv/activate.sh
autoenv_cd "$@"
else
builtin cd "$@"
fi
}
alias md='mkdir -p' alias md='mkdir -p'
alias rd=rmdir alias rd=rmdir
alias d='dirs -v | head -10' alias d='dirs -v | head -10'
# List directory contents
alias lsa='ls -lah'
alias l='ls -la'
alias ll='ls -l'
alias la='ls -lA'
# Push and pop directories on directory stack
alias pu='pushd'
alias po='popd'
...@@ -6,6 +6,15 @@ fi ...@@ -6,6 +6,15 @@ fi
HISTSIZE=10000 HISTSIZE=10000
SAVEHIST=10000 SAVEHIST=10000
# Show history
case $HIST_STAMPS in
"mm/dd/yyyy") alias history='fc -fl 1' ;;
"dd.mm.yyyy") alias history='fc -El 1' ;;
"yyyy-mm-dd") alias history='fc -il 1' ;;
*) alias history='fc -l 1' ;;
esac
setopt append_history
setopt extended_history setopt extended_history
setopt hist_expire_dups_first setopt hist_expire_dups_first
setopt hist_ignore_dups # ignore duplication command history list setopt hist_ignore_dups # ignore duplication command history list
......
...@@ -64,6 +64,9 @@ autoload -U edit-command-line ...@@ -64,6 +64,9 @@ autoload -U edit-command-line
zle -N edit-command-line zle -N edit-command-line
bindkey '\C-x\C-e' edit-command-line bindkey '\C-x\C-e' edit-command-line
# file rename magick
bindkey "^[m" copy-prev-shell-word
# consider emacs keybindings: # consider emacs keybindings:
#bindkey -e ## emacs key bindings #bindkey -e ## emacs key bindings
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
autoload -U url-quote-magic autoload -U url-quote-magic
zle -N self-insert url-quote-magic zle -N self-insert url-quote-magic
## file rename magick
bindkey "^[m" copy-prev-shell-word
## jobs ## jobs
setopt long_list_jobs setopt long_list_jobs
...@@ -12,4 +9,14 @@ setopt long_list_jobs ...@@ -12,4 +9,14 @@ setopt long_list_jobs
export PAGER="less" export PAGER="less"
export LESS="-R" export LESS="-R"
export LC_CTYPE=$LANG ## super user alias
alias _='sudo'
alias please='sudo'
## more intelligent acking for ubuntu users
alias afind='ack-grep -il'
# only define LC_CTYPE if undefined
if [[ -z "$LC_CTYPE" && -z "$LC_ALL" ]]; then
export LC_CTYPE=${LANG%%:*} # pick the first entry from LANG
fi
#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title # Set terminal window and tab/icon title
#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 #
#Fully support screen, iterm, and probably most modern xterm and rxvt # usage: title short_tab_title [long_window_title]
#
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
# Fully supports screen, iterm, and probably most modern xterm and rxvt
# (In screen, only short_tab_title is used)
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
function title { function title {
if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == *term* ]]; then [[ "$EMACS" == *term* ]] && return
return
fi # if $2 is unset use $1 as default
# if it is set and empty, leave it as is
: ${2=$1}
if [[ "$TERM" == screen* ]]; then if [[ "$TERM" == screen* ]]; then
print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars
elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ $TERM == ansi ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then elif [[ "$TERM" == xterm* ]] || [[ "$TERM" == rxvt* ]] || [[ "$TERM" == ansi ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;$2:q\a" #set window name print -Pn "\e]2;$2:q\a" #set window name
print -Pn "\e]1;$1:q\a" #set icon (=tab) name print -Pn "\e]1;$1:q\a" #set icon (=tab) name
fi fi
...@@ -16,13 +24,28 @@ function title { ...@@ -16,13 +24,28 @@ function title {
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
#Appears when you have the prompt # Runs before showing the prompt
function omz_termsupport_precmd { function omz_termsupport_precmd {
if [[ $DISABLE_AUTO_TITLE == true ]]; then
return
fi
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
# Notify Terminal.app of current directory using undocumented OSC sequence
# found in OS X 10.9 and 10.10's /etc/bashrc
if [[ $TERM_PROGRAM == Apple_Terminal ]] && [[ -z $INSIDE_EMACS ]]; then
local PWD_URL="file://$HOSTNAME${PWD// /%20}"
printf '\e]7;%s\a' "$PWD_URL"
fi
} }
#Appears at the beginning of (and during) of command execution # Runs before executing the command
function omz_termsupport_preexec { function omz_termsupport_preexec {
if [[ $DISABLE_AUTO_TITLE == true ]]; then
return
fi
emulate -L zsh emulate -L zsh
setopt extended_glob setopt extended_glob
...@@ -33,18 +56,5 @@ function omz_termsupport_preexec { ...@@ -33,18 +56,5 @@ function omz_termsupport_preexec {
title '$CMD' '%100>...>$LINE%<<' title '$CMD' '%100>...>$LINE%<<'
} }
#Appears each time pwd is changed
function omz_termsupport_chpwd {
#Notify Terminal.app of current directory using undocumented OSC sequence
#found in OS X 10.10's /etc/bashrc
if [[ $TERM_PROGRAM == Apple_Terminal ]] && [[ -z $INSIDE_EMACS ]]; then
local PWD_URL="file://$HOSTNAME${PWD// /%20}"
printf '\e]7;%s\a' "$PWD_URL"
fi
}
#Fire it once so the pwd is set properly upon shell startup
omz_termsupport_chpwd
precmd_functions+=(omz_termsupport_precmd) precmd_functions+=(omz_termsupport_precmd)
preexec_functions+=(omz_termsupport_preexec) preexec_functions+=(omz_termsupport_preexec)
chpwd_functions+=(omz_termsupport_chpwd)
# ls colors # ls colors
autoload colors; colors; autoload -U colors && colors
export LSCOLORS="Gxfxcxdxbxegedabagacad" export LSCOLORS="Gxfxcxdxbxegedabagacad"
#export LS_COLORS
# Enable ls colors # Enable ls colors
if [ "$DISABLE_LS_COLORS" != "true" ] if [ "$DISABLE_LS_COLORS" != "true" ]
then then
# Find the option for using colors in ls, depending on the version: Linux or BSD # Find the option for using colors in ls, depending on the version: Linux or BSD
if [[ "$(uname -s)" == "NetBSD" ]]; then if [[ "$(uname -s)" == "NetBSD" ]]; then
# On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors); # On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors);
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G # otherwise, leave ls as is, because NetBSD's ls doesn't support -G
gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty' gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
elif [[ "$(uname -s)" == "OpenBSD" ]]; then elif [[ "$(uname -s)" == "OpenBSD" ]]; then
...@@ -23,7 +22,7 @@ fi ...@@ -23,7 +22,7 @@ fi
#setopt no_beep #setopt no_beep
setopt auto_cd setopt auto_cd
setopt multios setopt multios
setopt cdablevarS setopt cdablevars
if [[ x$WINDOW != x ]] if [[ x$WINDOW != x ]]
then then
...@@ -43,4 +42,3 @@ ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is c ...@@ -43,4 +42,3 @@ ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is c
# Setup the prompt with pretty colors # Setup the prompt with pretty colors
setopt prompt_subst setopt prompt_subst
_ant_does_target_list_need_generating () { _ant_does_target_list_need_generating () {
[ ! -f .ant_targets ] && return 0; [ ! -f .ant_targets ] && return 0;
[ .ant_targets -nt build.xml ] && return 0; [ build.xml -nt .ant_targets ] && return 0;
return 1; return 1;
} }
_ant () { _ant () {
if [ -f build.xml ]; then if [ -f build.xml ]; then
if _ant_does_target_list_need_generating; then if _ant_does_target_list_need_generating; then
sed -n '/<target/s/<target.*name="\([^"]*\).*$/\1/p' build.xml > .ant_targets ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
fi fi
compadd `cat .ant_targets` compadd -- `cat .ant_targets`
fi fi
} }
......
# Activates autoenv or reports its failure
if ! source $HOME/.autoenv/activate.sh 2>/dev/null; then
echo '-------- AUTOENV ---------'
echo 'Could not find ~/.autoenv/activate.sh.'
echo 'Please check if autoenv is correctly installed.'
echo 'In the meantime the autoenv plugin is DISABLED.'
echo '--------------------------'
return 1
fi
# The use_env call below is a reusable command to activate/create a new Python # The use_env call below is a reusable command to activate/create a new Python
# virtualenv, requiring only a single declarative line of code in your .env files. # virtualenv, requiring only a single declarative line of code in your .env files.
# It only performs an action if the requested virtualenv is not the current one. # It only performs an action if the requested virtualenv is not the current one.
use_env() { use_env() {
typeset venv typeset venv
venv="$1" venv="$1"
......
...@@ -15,7 +15,7 @@ _cake_does_target_list_need_generating () { ...@@ -15,7 +15,7 @@ _cake_does_target_list_need_generating () {
fi fi
[ ! -f ${_cake_task_cache_file} ] && return 0; [ ! -f ${_cake_task_cache_file} ] && return 0;
[ ${_cake_task_cache_file} -nt Cakefile ] && return 0; [ Cakefile -nt ${_cake_task_cache_file} ] && return 0;
return 1; return 1;
} }
......
...@@ -7,3 +7,19 @@ ...@@ -7,3 +7,19 @@
# Arch Linux command-not-found support, you must have package pkgfile installed # Arch Linux command-not-found support, you must have package pkgfile installed
# https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook # https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook
[[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh [[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
# Fedora command-not-found support
if [ -f /usr/libexec/pk-command-not-found ]; then
command_not_found_handler () {
runcnf=1
retval=127
[ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0
[ ! -x /usr/libexec/packagekitd ] && runcnf=0
if [ $runcnf -eq 1 ]
then
/usr/libexec/pk-command-not-found $@
retval=$?
fi
return $retval
}
fi
...@@ -20,12 +20,6 @@ alias sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} ' ...@@ -20,12 +20,6 @@ alias sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} '
alias t='tail -f' alias t='tail -f'
# because typing 'cd' is A LOT of work!!
alias ..='cd ../'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
# Command line head / tail shortcuts # Command line head / tail shortcuts
alias -g H='| head' alias -g H='| head'
alias -g T='| tail' alias -g T='| tail'
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
# Composer basic command completion # Composer basic command completion
_composer_get_command_list () { _composer_get_command_list () {
composer --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }' $_comp_command1 --no-ansi | sed "1,/Available commands/d" | awk '/^\s*[a-z]+/ { print $1 }'
} }
_composer_get_required_list () { _composer_get_required_list () {
composer show -s --no-ansi | sed '1,/requires/d' | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }' $_comp_command1 show -s --no-ansi | sed '1,/requires/d' | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }'
} }
_composer () { _composer () {
...@@ -20,29 +20,30 @@ _composer () { ...@@ -20,29 +20,30 @@ _composer () {
_arguments \ _arguments \
'1: :->command'\ '1: :->command'\
'*: :->args' '*: :->args'
if [ -f composer.json ]; then
case $state in case $state in
command) command)
compadd `_composer_get_command_list` compadd $(_composer_get_command_list)
;; ;;
*) *)
compadd `_composer_get_required_list` compadd $(_composer_get_required_list)
;; ;;
esac esac
else
compadd create-project init search selfupdate show
fi
} }
compdef _composer composer compdef _composer composer
compdef _composer composer.phar
# Aliases # Aliases
alias c='composer' alias c='composer'
alias csu='composer self-update' alias csu='composer self-update'
alias cu='composer update' alias cu='composer update'
alias cr='composer require'
alias ci='composer install' alias ci='composer install'
alias ccp='composer create-project' alias ccp='composer create-project'
alias cdu='composer dump-autoload' alias cdu='composer dump-autoload'
alias cgu='composer global update'
alias cgr='composer global require'
# install composer in the current directory # install composer in the current directory
alias cget='curl -s https://getcomposer.org/installer | php' alias cget='curl -s https://getcomposer.org/installer | php'
......
## # enables cycling through the directory stack using
# dircycle plugin: enables cycling through the directory # Ctrl+Shift+Left/Right
# stack using Ctrl+Shift+Left/Right #
# left/right direction follows the order in which directories
# were visited, like left/right arrows do in a browser
eval "insert-cycledleft () { zle push-line; LBUFFER='pushd -q +1'; zle accept-line }" # NO_PUSHD_MINUS syntax:
# pushd +N: start counting from left of `dirs' output
# pushd -N: start counting from right of `dirs' output
insert-cycledleft () {
emulate -L zsh
setopt nopushdminus
builtin pushd -q +1 &>/dev/null || true
zle reset-prompt
}
zle -N insert-cycledleft zle -N insert-cycledleft
bindkey "\e[1;6D" insert-cycledleft
eval "insert-cycledright () { zle push-line; LBUFFER='pushd -q +0'; zle accept-line }" insert-cycledright () {
emulate -L zsh
setopt nopushdminus
builtin pushd -q -0 &>/dev/null || true
zle reset-prompt
}
zle -N insert-cycledright zle -N insert-cycledright
bindkey "\e[1;6C" insert-cycledright
# add key bindings for iTerm2
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
bindkey "^[[1;6D" insert-cycledleft
bindkey "^[[1;6C" insert-cycledright
else
bindkey "\e[1;6D" insert-cycledleft
bindkey "\e[1;6C" insert-cycledright
fi
\ No newline at end of file
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
# http://github.com/olivierverdier/zsh-git-prompt # http://github.com/olivierverdier/zsh-git-prompt
# #
export __GIT_PROMPT_DIR=$ZSH/plugins/git-prompt export __GIT_PROMPT_DIR=$ZSH/plugins/git-prompt
# Initialize colors.
autoload -U colors
colors
# Allow for functions in the prompt. # Allow for functions in the prompt.
setopt PROMPT_SUBST setopt PROMPT_SUBST
......
...@@ -27,7 +27,6 @@ unmark() { ...@@ -27,7 +27,6 @@ unmark() {
rm -i "$MARKPATH/$1" rm -i "$MARKPATH/$1"
} }
autoload colors
marks() { marks() {
for link in $MARKPATH/*(@); do for link in $MARKPATH/*(@); do
local markname="$fg[cyan]${link:t}$reset_color" local markname="$fg[cyan]${link:t}$reset_color"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Flag indicating if we've previously jumped to last directory. # Flag indicating if we've previously jumped to last directory.
typeset -g ZSH_LAST_WORKING_DIRECTORY typeset -g ZSH_LAST_WORKING_DIRECTORY
mkdir -p $ZSH_CACHE_DIR mkdir -p $ZSH_CACHE_DIR
local cache_file="$ZSH_CACHE_DIR/last-working-dir" cache_file="$ZSH_CACHE_DIR/last-working-dir"
# Updates the last directory once directory is changed. # Updates the last directory once directory is changed.
function chpwd() { function chpwd() {
......
...@@ -13,9 +13,8 @@ ...@@ -13,9 +13,8 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
sudo-command-line() { sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history [[ -z $BUFFER ]] && zle up-history
[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER" [[ $BUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER"
zle end-of-line
} }
zle -N sudo-command-line zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc] # Defined shortcut keys: [Esc] [Esc]
......
...@@ -14,6 +14,14 @@ function zle-keymap-select zle-line-init zle-line-finish { ...@@ -14,6 +14,14 @@ function zle-keymap-select zle-line-init zle-line-finish {
zle -R zle -R
} }
# Ensure that the prompt is redrawn when the terminal size changes.
TRAPWINCH() {
if [[ -o zle ]]; then
zle reset-prompt
zle -R
fi
}
zle -N zle-line-init zle -N zle-line-init
zle -N zle-line-finish zle -N zle-line-finish
zle -N zle-keymap-select zle -N zle-keymap-select
......
virtualenvwrapper='virtualenvwrapper.sh' virtualenvwrapper='virtualenvwrapper.sh'
if (( $+commands[$virtualenvwrapper] )); then
if (( $+commands[$virtualenvwrapper] )); then
source ${${virtualenvwrapper}:c} source ${${virtualenvwrapper}:c}
elif [[ -f "/etc/bash_completion.d/virtualenvwrapper" ]]; then
virtualenvwrapper="/etc/bash_completion.d/virtualenvwrapper"
source "/etc/bash_completion.d/virtualenvwrapper"
else
print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}.\n"\
"Please install with \`pip install virtualenvwrapper\`" >&2
return
fi
if ! type workon &>/dev/null; then
print "zsh virtualenvwrapper plugin: shell function 'workon' not defined.\n"\
"Please check ${virtualenvwrapper}" >&2
return
fi
if [[ "$WORKON_HOME" == "" ]]; then if [[ "$WORKON_HOME" == "" ]]; then
echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" print "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" >&2
else return
fi
if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
# Automatically activate Git projects's virtual environments based on the # Automatically activate Git projects's virtual environments based on the
# directory name of the project. Virtual environment name can be overridden # directory name of the project. Virtual environment name can be overridden
# by placing a .venv file in the project root with a virtualenv name in it # by placing a .venv file in the project root with a virtualenv name in it
function workon_cwd { function workon_cwd {
if [ ! $WORKON_CWD ]; then if [ ! $WORKON_CWD ]; then
WORKON_CWD=1 WORKON_CWD=1
# Check if this is a Git repo # Check if this is a Git repo
PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null` PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
if (( $? != 0 )); then if (( $? != 0 )); then
PROJECT_ROOT="." PROJECT_ROOT="."
fi fi
# Check for virtualenv name override # Check for virtualenv name override
if [[ -f "$PROJECT_ROOT/.venv" ]]; then if [[ -f "$PROJECT_ROOT/.venv" ]]; then
ENV_NAME=`cat "$PROJECT_ROOT/.venv"` ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
ENV_NAME="$PROJECT_ROOT/.venv" ENV_NAME="$PROJECT_ROOT/.venv"
elif [[ "$PROJECT_ROOT" != "." ]]; then elif [[ "$PROJECT_ROOT" != "." ]]; then
ENV_NAME=`basename "$PROJECT_ROOT"` ENV_NAME=`basename "$PROJECT_ROOT"`
else else
ENV_NAME="" ENV_NAME=""
fi fi
if [[ "$ENV_NAME" != "" ]]; then if [[ "$ENV_NAME" != "" ]]; then
# Activate the environment only if it is not already active # Activate the environment only if it is not already active
if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
elif [[ -e "$ENV_NAME/bin/activate" ]]; then elif [[ -e "$ENV_NAME/bin/activate" ]]; then
source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
fi
fi
elif [ $CD_VIRTUAL_ENV ]; then
# We've just left the repo, deactivate the environment
# Note: this only happens if the virtualenv was activated automatically
deactivate && unset CD_VIRTUAL_ENV
fi fi
unset PROJECT_ROOT
unset WORKON_CWD
fi
}
# Append workon_cwd to the chpwd_functions array, so it will be called on cd
# http://zsh.sourceforge.net/Doc/Release/Functions.html
# TODO: replace with 'add-zsh-hook chpwd workon_cwd' when oh-my-zsh min version is raised above 4.3.4
if (( ${+chpwd_functions} )); then
if (( $chpwd_functions[(I)workon_cwd] == 0 )); then
set -A chpwd_functions $chpwd_functions workon_cwd
fi fi
else elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then
set -A chpwd_functions workon_cwd # We've just left the repo, deactivate the environment
# Note: this only happens if the virtualenv was activated automatically
deactivate && unset CD_VIRTUAL_ENV
fi fi
unset PROJECT_ROOT
unset WORKON_CWD
fi fi
}
# Append workon_cwd to the chpwd_functions array, so it will be called on cd
# http://zsh.sourceforge.net/Doc/Release/Functions.html
if ! (( $chpwd_functions[(I)workon_cwd] )); then
chpwd_functions+=(workon_cwd)
fi fi
else
print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`."
fi fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment