From 1e7c6743a7b221cb2069a84c70890014597672d8 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Mon, 15 Sep 2014 15:36:34 +0200 Subject: sudo: maintain cursor position I.e. when prefixing the current command-line with 'sudo ' maintain the current cursor position instead of jumping to the end of the line. --- plugins/sudo/sudo.plugin.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/sudo/sudo.plugin.zsh b/plugins/sudo/sudo.plugin.zsh index d12e06853..e3ba39918 100644 --- a/plugins/sudo/sudo.plugin.zsh +++ b/plugins/sudo/sudo.plugin.zsh @@ -13,9 +13,8 @@ # ------------------------------------------------------------------------------ sudo-command-line() { -[[ -z $BUFFER ]] && zle up-history -[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER" -zle end-of-line + [[ -z $BUFFER ]] && zle up-history + [[ $BUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER" } zle -N sudo-command-line # Defined shortcut keys: [Esc] [Esc] -- cgit v1.2.3-70-g09d2 From 833e6f5958b9851d2dbcf8ae706474af4079a25e Mon Sep 17 00:00:00 2001 From: Jyrki Pulliainen Date: Wed, 7 Jan 2015 18:15:00 +0100 Subject: virtualenvwrapper: Deactivate only if in virtualenv If user manually deactivates the virtualenv when using this mode, zsh will produce following error: deactivate:12: command not found: virtualenv_deactivate To avoid this, check that the VIRTUAL_ENV flag is set before trying to automatically deactivate the virtual environment. Fixes #2185 --- plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index 52e02d3e0..217ab0722 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -38,7 +38,7 @@ if (( $+commands[$virtualenvwrapper] )); then source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" fi fi - elif [ $CD_VIRTUAL_ENV ]; then + elif [[ -n $CD_VIRTUAL_ENV && -n $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 -- cgit v1.2.3-70-g09d2 From f997ed7ed8028e400216cfac9bee64b53017e588 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 10 Jan 2015 15:38:49 +0100 Subject: Add Fedora support for command-not-found plugin --- plugins/command-not-found/command-not-found.plugin.zsh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'plugins') diff --git a/plugins/command-not-found/command-not-found.plugin.zsh b/plugins/command-not-found/command-not-found.plugin.zsh index f3d7ec2df..797554a13 100644 --- a/plugins/command-not-found/command-not-found.plugin.zsh +++ b/plugins/command-not-found/command-not-found.plugin.zsh @@ -7,3 +7,19 @@ # Arch Linux command-not-found support, you must have package pkgfile installed # 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 + +# 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 -- cgit v1.2.3-70-g09d2 From e60458793ab9703bb65adb6c326f43c6bd5fd126 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 17 Dec 2014 11:11:53 +0100 Subject: Switch newer-than logic to get the desired behavior In the old version, the function returned true (0) if the cache file was newer than the Cakefile, which was *always* unless the Cakefile had been updated. Therefore we generated the file every time unless the Cakefile was updated, which was precisely when we needed to regenerate the cache file. Now it generates the cache file only when the Cakefile has been updated. --- plugins/cake/cake.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/cake/cake.plugin.zsh b/plugins/cake/cake.plugin.zsh index 44cc47470..2370df949 100644 --- a/plugins/cake/cake.plugin.zsh +++ b/plugins/cake/cake.plugin.zsh @@ -15,7 +15,7 @@ _cake_does_target_list_need_generating () { fi [ ! -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; } -- cgit v1.2.3-70-g09d2 From 8ccfc3d444a36905003397083ac5ece46eda2a3b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 9 Jan 2015 08:33:51 +1300 Subject: Removing 'local' usage to prevent issue when installed with antigen Error encountered when installed with antigen: "chpwd:2: no such file or directory:". Solution described in https://github.com/zsh-users/antigen/issues/75 --- plugins/last-working-dir/last-working-dir.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/last-working-dir/last-working-dir.plugin.zsh b/plugins/last-working-dir/last-working-dir.plugin.zsh index e472578b0..4fa6fcc34 100644 --- a/plugins/last-working-dir/last-working-dir.plugin.zsh +++ b/plugins/last-working-dir/last-working-dir.plugin.zsh @@ -5,7 +5,7 @@ # Flag indicating if we've previously jumped to last directory. typeset -g ZSH_LAST_WORKING_DIRECTORY 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. function chpwd() { -- cgit v1.2.3-70-g09d2 From 7de44dbdb767e52e509010b1468126259e0b8b87 Mon Sep 17 00:00:00 2001 From: Gabor Marton Date: Wed, 4 Feb 2015 12:56:58 +0100 Subject: Added trapwinch to vi-mode plugin. --- plugins/vi-mode/vi-mode.plugin.zsh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'plugins') diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 3ed32b3fb..f2745b409 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -14,6 +14,14 @@ function zle-keymap-select zle-line-init zle-line-finish { 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-finish zle -N zle-keymap-select -- cgit v1.2.3-70-g09d2 From 7f636ba5901b1abe9bb01d94b9e290bed982a873 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Mon, 17 Nov 2014 20:38:22 -0800 Subject: Backwards logic in newer check. Regen .ant_targets only if it's newer than build.xml? Yeah, that seems wrong. --- plugins/ant/ant.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/ant/ant.plugin.zsh b/plugins/ant/ant.plugin.zsh index 45f2b06eb..38d13f2a8 100644 --- a/plugins/ant/ant.plugin.zsh +++ b/plugins/ant/ant.plugin.zsh @@ -1,6 +1,6 @@ _ant_does_target_list_need_generating () { [ ! -f .ant_targets ] && return 0; - [ .ant_targets -nt build.xml ] && return 0; + [ build.xml -nt .ant_targets ] && return 0; return 1; } -- cgit v1.2.3-70-g09d2 From 013b2bffcf11d0bc3ff29c96a8e6846166639c2c Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Mon, 17 Nov 2014 20:43:19 -0800 Subject: Change ant target enumeration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make use of ant's project help feature instead of trying to parse XML with regex (see: http://stackoverflow.com/a/1732454/740787). This is a behavioral change that does a few things: • adds support for ant imports, which were previously not recognized as possibly containing targets • supresses targets with no description, as these are conventionally for internal use only --- plugins/ant/ant.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/ant/ant.plugin.zsh b/plugins/ant/ant.plugin.zsh index 38d13f2a8..a945967d5 100644 --- a/plugins/ant/ant.plugin.zsh +++ b/plugins/ant/ant.plugin.zsh @@ -7,7 +7,7 @@ _ant_does_target_list_need_generating () { _ant () { if [ -f build.xml ]; then if _ant_does_target_list_need_generating; then - sed -n '/ .ant_targets + ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets fi compadd `cat .ant_targets` fi -- cgit v1.2.3-70-g09d2 From 349493a0b81ae98117ea1a115a92ba509476298f Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Mon, 9 Feb 2015 12:43:51 -0800 Subject: Fix for ant targets with leading dash As suggested in https://github.com/robbyrussell/oh-my-zsh/pull/3329#issuecomment-72062236 --- plugins/ant/ant.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/ant/ant.plugin.zsh b/plugins/ant/ant.plugin.zsh index a945967d5..0b738c94f 100644 --- a/plugins/ant/ant.plugin.zsh +++ b/plugins/ant/ant.plugin.zsh @@ -9,7 +9,7 @@ _ant () { if _ant_does_target_list_need_generating; then ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets fi - compadd `cat .ant_targets` + compadd -- `cat .ant_targets` fi } -- cgit v1.2.3-70-g09d2 From 5fe22fcbc6364aaacce373d71fa7d6b6f2d11a33 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 16 Dec 2014 00:43:01 +0100 Subject: Clean up and fix +1/-0 syntax to work as expected This change follows this proposed behaviour: Ctrl+Shift+Left: move to last visited directory Ctrl+Shift+Right: move to next visited directory an alternative behaviour would be: Ctrl+Shift+Left: move directory to the left in `dirs` output Ctrl+Shift+Right: move directory to the right in `dirs` output It also introduces `setopt nopushdminus` as a way to standardise pushd syntax. It's value wasn't clear before, which has been the cause of so many pull requests regarding this plugin not working in some environments. --- plugins/dircycle/dircycle.plugin.zsh | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh index c6b6ba785..2064af46a 100644 --- a/plugins/dircycle/dircycle.plugin.zsh +++ b/plugins/dircycle/dircycle.plugin.zsh @@ -1,10 +1,27 @@ -## -# dircycle plugin: enables cycling through the directory -# stack using Ctrl+Shift+Left/Right +# enables cycling through the directory 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 +setopt nopushdminus + +insert-cycledleft () { + zle push-line + LBUFFER='pushd -q +1' + zle accept-line +} 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 () { + zle push-line + LBUFFER='pushd -q -0' + zle accept-line +} zle -N insert-cycledright + +bindkey "\e[1;6D" insert-cycledleft bindkey "\e[1;6C" insert-cycledright -- cgit v1.2.3-70-g09d2 From e93fd939adb69a498ba1296b1ce0c99786e26084 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 16 Dec 2014 01:29:06 +0100 Subject: Run pushd command directly and trigger prompt redraw --- plugins/dircycle/dircycle.plugin.zsh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh index 2064af46a..1c4a0175a 100644 --- a/plugins/dircycle/dircycle.plugin.zsh +++ b/plugins/dircycle/dircycle.plugin.zsh @@ -10,16 +10,14 @@ setopt nopushdminus insert-cycledleft () { - zle push-line - LBUFFER='pushd -q +1' - zle accept-line + builtin pushd -q +1 &>/dev/null || true + zle reset-prompt } zle -N insert-cycledleft insert-cycledright () { - zle push-line - LBUFFER='pushd -q -0' - zle accept-line + builtin pushd -q -0 &>/dev/null || true + zle reset-prompt } zle -N insert-cycledright -- cgit v1.2.3-70-g09d2 From 999bab187c0a59301f4055fb6239a5352d3c96ab Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 20 Dec 2014 20:35:52 +0100 Subject: Emulate zsh in zlewidgets instead of static setopt command This way the user can keep their preferred pushd syntax while enabling us to use a standard syntax in our defined functions. To explain further, without a clear value on the PUSHD_MINUS option, we could be changing the +1/-0 values all we want, that some user would find that it didn't work for him. We have two options, then: - Setting a particular value, which was my first approach. - Using `emulate -L zsh` to ensure all options defined in the function's body won't be passed along to the main zsh instance. For more info see: http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html#index-emulate --- plugins/dircycle/dircycle.plugin.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh index 1c4a0175a..12b20ab04 100644 --- a/plugins/dircycle/dircycle.plugin.zsh +++ b/plugins/dircycle/dircycle.plugin.zsh @@ -7,15 +7,20 @@ # NO_PUSHD_MINUS syntax: # pushd +N: start counting from left of `dirs' output # pushd -N: start counting from right of `dirs' output -setopt nopushdminus insert-cycledleft () { + emulate -L zsh + setopt nopushdminus + builtin pushd -q +1 &>/dev/null || true zle reset-prompt } zle -N insert-cycledleft insert-cycledright () { + emulate -L zsh + setopt nopushdminus + builtin pushd -q -0 &>/dev/null || true zle reset-prompt } -- cgit v1.2.3-70-g09d2 From 282240bf37d6fd9979da2c3a41006824dbb4e268 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 24 Dec 2014 01:33:28 +0100 Subject: Account for iTerm2 sent keys in dircycle plugin --- plugins/dircycle/dircycle.plugin.zsh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh index 12b20ab04..1e31105b1 100644 --- a/plugins/dircycle/dircycle.plugin.zsh +++ b/plugins/dircycle/dircycle.plugin.zsh @@ -26,5 +26,12 @@ insert-cycledright () { } zle -N insert-cycledright -bindkey "\e[1;6D" insert-cycledleft -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 -- cgit v1.2.3-70-g09d2 From ace98846eac9726f7161617291e1fd2affc3f4eb Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Fri, 10 Jan 2014 23:40:22 +0100 Subject: Pushes autoenv code to its plugin. Sources the activate.sh file or informs the user, that its not available. Overriding the cd function, as it was formerly done, is not needed anymore, activate.sh does this by itself. --- plugins/autoenv/autoenv.plugin.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'plugins') diff --git a/plugins/autoenv/autoenv.plugin.zsh b/plugins/autoenv/autoenv.plugin.zsh index ca5666979..a8271849e 100644 --- a/plugins/autoenv/autoenv.plugin.zsh +++ b/plugins/autoenv/autoenv.plugin.zsh @@ -1,6 +1,17 @@ +# 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 # 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. + use_env() { typeset venv venv="$1" -- cgit v1.2.3-70-g09d2 From 724143c3297249961977a957d8fa1bc92cd7be2c Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Sat, 11 Jan 2014 00:04:53 +0100 Subject: Deletes dot aliases from common-aliases. They are implemented in lib anyway. --- plugins/common-aliases/common-aliases.plugin.zsh | 6 ------ 1 file changed, 6 deletions(-) (limited to 'plugins') diff --git a/plugins/common-aliases/common-aliases.plugin.zsh b/plugins/common-aliases/common-aliases.plugin.zsh index 90d59910c..e3830adcf 100644 --- a/plugins/common-aliases/common-aliases.plugin.zsh +++ b/plugins/common-aliases/common-aliases.plugin.zsh @@ -20,12 +20,6 @@ alias sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} ' 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 alias -g H='| head' alias -g T='| tail' -- cgit v1.2.3-70-g09d2 From 2193135ebc4ce0778ff6949b448e4526dbd34284 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 9 Feb 2015 20:43:48 +0100 Subject: Clean up appearance lib file and redundant `colors` calls in other files --- lib/theme-and-appearance.zsh | 8 +++----- plugins/git-prompt/git-prompt.plugin.zsh | 3 --- plugins/jump/jump.plugin.zsh | 1 - themes/adben.zsh-theme | 15 ++++++--------- themes/apple.zsh-theme | 1 - themes/gnzh.zsh-theme | 3 +-- themes/half-life.zsh-theme | 2 -- themes/jonathan.zsh-theme | 5 +---- themes/kolo.zsh-theme | 2 -- themes/mikeh.zsh-theme | 2 -- themes/simonoff.zsh-theme | 5 +---- themes/steeef.zsh-theme | 2 -- themes/zhann.zsh-theme | 2 -- 13 files changed, 12 insertions(+), 39 deletions(-) (limited to 'plugins') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 0353f9db4..926303ca4 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -1,14 +1,13 @@ # ls colors -autoload colors; colors; +autoload -U colors && colors export LSCOLORS="Gxfxcxdxbxegedabagacad" -#export LS_COLORS # Enable ls colors if [ "$DISABLE_LS_COLORS" != "true" ] then # Find the option for using colors in ls, depending on the version: Linux or BSD 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 gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty' elif [[ "$(uname -s)" == "OpenBSD" ]]; then @@ -23,7 +22,7 @@ fi #setopt no_beep setopt auto_cd setopt multios -setopt cdablevarS +setopt cdablevars if [[ x$WINDOW != x ]] then @@ -43,4 +42,3 @@ ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is c # Setup the prompt with pretty colors setopt prompt_subst - diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh index 01b8a88d9..d868a5fe1 100644 --- a/plugins/git-prompt/git-prompt.plugin.zsh +++ b/plugins/git-prompt/git-prompt.plugin.zsh @@ -2,9 +2,6 @@ # http://github.com/olivierverdier/zsh-git-prompt # export __GIT_PROMPT_DIR=$ZSH/plugins/git-prompt -# Initialize colors. -autoload -U colors -colors # Allow for functions in the prompt. setopt PROMPT_SUBST diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index b16814fe4..d082c11e5 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -27,7 +27,6 @@ unmark() { rm -i "$MARKPATH/$1" } -autoload colors marks() { for link in $MARKPATH/*(@); do local markname="$fg[cyan]${link:t}$reset_color" diff --git a/themes/adben.zsh-theme b/themes/adben.zsh-theme index 6869c8a20..212b823a5 100644 --- a/themes/adben.zsh-theme +++ b/themes/adben.zsh-theme @@ -69,17 +69,17 @@ function precmd { #Choose from all databases, regardless of whether they are considered "offensive" fortune -a } - #obtains the tip + #obtains the tip ps1_command_tip () { wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed 1d | sed '/^$/d' - } + } prompt_header () { if [[ "true" == "$ENABLE_COMMAND_TIP" ]]; then ps1_command_tip else ps1_fortune - fi - } + fi + } PROMPT_HEAD="${RED_START}${PR_YELLOW}$(prompt_header)${PR_RESET}" # set a simple variable to show when in screen if [[ -n "${WINDOW}" ]]; then @@ -99,11 +99,8 @@ prompt_context () { set_prompt () { # required for the prompt setopt prompt_subst - autoload colors zsh/terminfo - if [[ "$terminfo[colors]" -gt 8 ]]; then - colors - fi - + autoload zsh/terminfo + # ######### PROMPT ######### PROMPT='${PROMPT_HEAD} ${RED_START}$(prompt_context) diff --git a/themes/apple.zsh-theme b/themes/apple.zsh-theme index 275341dc6..95e6249fa 100644 --- a/themes/apple.zsh-theme +++ b/themes/apple.zsh-theme @@ -7,7 +7,6 @@ get_git_dirty() { } autoload -Uz vcs_info -autoload -U colors && colors zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' unstagedstr '%F{red}*' # display this when there are unstaged changes zstyle ':vcs_info:*' stagedstr '%F{yellow}+' # display this when there are staged changes diff --git a/themes/gnzh.zsh-theme b/themes/gnzh.zsh-theme index 0519fbefb..ab154c1e5 100644 --- a/themes/gnzh.zsh-theme +++ b/themes/gnzh.zsh-theme @@ -2,8 +2,7 @@ # Based on bira theme # load some modules -autoload -U colors zsh/terminfo # Used in the colour alias below -colors +autoload -U zsh/terminfo # Used in the colour alias below setopt prompt_subst # make some aliases for the colours: (could use normal escape sequences too) diff --git a/themes/half-life.zsh-theme b/themes/half-life.zsh-theme index 942affa94..a3c505706 100644 --- a/themes/half-life.zsh-theme +++ b/themes/half-life.zsh-theme @@ -13,8 +13,6 @@ function virtualenv_info { PR_GIT_UPDATE=1 setopt prompt_subst -autoload colors -colors autoload -U add-zsh-hook autoload -Uz vcs_info diff --git a/themes/jonathan.zsh-theme b/themes/jonathan.zsh-theme index bca92970c..2f0e77431 100644 --- a/themes/jonathan.zsh-theme +++ b/themes/jonathan.zsh-theme @@ -44,10 +44,7 @@ setprompt () { ### # See if we can use colors. - autoload colors zsh/terminfo - if [[ "$terminfo[colors]" -ge 8 ]]; then - colors - fi + autoload zsh/terminfo for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' diff --git a/themes/kolo.zsh-theme b/themes/kolo.zsh-theme index e743289c3..51b0af724 100644 --- a/themes/kolo.zsh-theme +++ b/themes/kolo.zsh-theme @@ -1,5 +1,3 @@ -autoload -U colors && colors - autoload -Uz vcs_info zstyle ':vcs_info:*' stagedstr '%F{green}●' diff --git a/themes/mikeh.zsh-theme b/themes/mikeh.zsh-theme index 943f04d38..a95383ba5 100644 --- a/themes/mikeh.zsh-theme +++ b/themes/mikeh.zsh-theme @@ -1,6 +1,4 @@ setopt prompt_subst -autoload colors -colors autoload -U add-zsh-hook autoload -Uz vcs_info diff --git a/themes/simonoff.zsh-theme b/themes/simonoff.zsh-theme index fb4d32e24..63ce4261b 100644 --- a/themes/simonoff.zsh-theme +++ b/themes/simonoff.zsh-theme @@ -63,10 +63,7 @@ setprompt () { ### # See if we can use colors. - autoload colors zsh/terminfo - if [[ "$terminfo[colors]" -ge 8 ]]; then - colors - fi + autoload zsh/terminfo for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index e38188d35..13728ca9a 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -15,8 +15,6 @@ function virtualenv_info { PR_GIT_UPDATE=1 setopt prompt_subst -autoload colors -colors autoload -U add-zsh-hook autoload -Uz vcs_info diff --git a/themes/zhann.zsh-theme b/themes/zhann.zsh-theme index 5c0854730..27597ec6c 100644 --- a/themes/zhann.zsh-theme +++ b/themes/zhann.zsh-theme @@ -1,5 +1,3 @@ -autoload -U colors && colors - autoload -Uz vcs_info zstyle ':vcs_info:*' stagedstr '%F{green}●' -- cgit v1.2.3-70-g09d2 From 80d856e1655cc2b2e9d6899bae884631283a8063 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 26 Dec 2014 22:33:36 +0100 Subject: Clean up web-search plugin logic to allow easier changes --- plugins/web-search/web-search.plugin.zsh | 55 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'plugins') diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 28559deb9..1e661250a 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -1,42 +1,43 @@ # web_search from terminal function web_search() { - # get the open command - local open_cmd - if [[ "$OSTYPE" = darwin* ]]; then - open_cmd='open' - else - open_cmd='xdg-open' - fi + emulate -L zsh + + # define search engine URLS + typeset -A urls + urls=( + google "https://www.google.com/search?q=" + bing "https://www.bing.com/search?q=" + yahoo "https://www.yahoo.com/search?q=" + duckduckgo "https://www.duckduckgo.com/?q=" + ) + + # define the open command + case "$OSTYPE" in + darwin*) open_cmd="open" ;; + linux*) open_cmd="xdg-open" ;; + *) echo "Platform $OSTYPE not supported" + return 1 + ;; + esac # check whether the search engine is supported - if [[ ! $1 =~ '(google|bing|yahoo|duckduckgo)' ]]; - then + if [[ -z "$urls[$1]" ]]; then echo "Search engine $1 not supported." return 1 fi - local url="http://www.$1.com" - - # no keyword provided, simply open the search engine homepage - if [[ $# -le 1 ]]; then - $open_cmd "$url" - return - fi - if [[ $1 == 'duckduckgo' ]]; then - #slightly different search syntax for DDG - url="${url}/?q=" + # search or go to main page depending on number of arguments passed + if [[ $# -gt 1 ]]; then + # build search url: + # join arguments passed with '+', then append to search engine URL + url="${urls[$1]}${(j:+:)@[2,-1]}" else - url="${url}/search?q=" + # build main page url: + # split by '/', then rejoin protocol (1) and domain (2) parts with '//' + url="${(j://:)${(s:/:)urls[$1]}[1,2]}" fi - shift # shift out $1 - - while [[ $# -gt 0 ]]; do - url="${url}$1+" - shift - done - url="${url%?}" # remove the last '+' nohup $open_cmd "$url" >/dev/null 2&>1 } -- cgit v1.2.3-70-g09d2 From 80ba54a94fe7d7628d159823d5c63e12811c68b0 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 27 Dec 2014 02:27:24 +0100 Subject: Add Yandex support to web-search plugin --- plugins/web-search/web-search.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugins') diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 1e661250a..5e3c00d3c 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -10,6 +10,7 @@ function web_search() { bing "https://www.bing.com/search?q=" yahoo "https://www.yahoo.com/search?q=" duckduckgo "https://www.duckduckgo.com/?q=" + yandex "http://yandex.ru/yandsearch?text=" ) # define the open command @@ -46,6 +47,8 @@ alias bing='web_search bing' alias google='web_search google' alias yahoo='web_search yahoo' alias ddg='web_search duckduckgo' +alias yandex='web_search yandex' + #add your own !bang searches here alias wiki='web_search duckduckgo \!w' alias news='web_search duckduckgo \!n' -- cgit v1.2.3-70-g09d2 From adaea31ca013054094a45b009ab22382c4d94666 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 27 Dec 2014 02:30:16 +0100 Subject: Silence nohup output in web-search plugin --- plugins/web-search/web-search.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 5e3c00d3c..19f9cad33 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -39,7 +39,7 @@ function web_search() { url="${(j://:)${(s:/:)urls[$1]}[1,2]}" fi - nohup $open_cmd "$url" >/dev/null 2&>1 + nohup $open_cmd "$url" &>/dev/null } -- cgit v1.2.3-70-g09d2 From c45885093fd8fa3375286ef1dcba9bc296e08a80 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 27 Dec 2014 02:56:30 +0100 Subject: Add support for cygwin open in web-search plugin --- plugins/web-search/web-search.plugin.zsh | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins') diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 19f9cad33..52d03b2d0 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -16,6 +16,7 @@ function web_search() { # define the open command case "$OSTYPE" in darwin*) open_cmd="open" ;; + cygwin*) open_cmd="cygstart" ;; linux*) open_cmd="xdg-open" ;; *) echo "Platform $OSTYPE not supported" return 1 -- cgit v1.2.3-70-g09d2 From e8daf8150e923bfd30769e9a55c15daec523996b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sat, 27 Dec 2014 03:15:56 +0100 Subject: Fix yahoo search URL in web-search plugin --- plugins/web-search/web-search.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 52d03b2d0..b0a4a2926 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -8,7 +8,7 @@ function web_search() { urls=( google "https://www.google.com/search?q=" bing "https://www.bing.com/search?q=" - yahoo "https://www.yahoo.com/search?q=" + yahoo "https://search.yahoo.com/search?p=" duckduckgo "https://www.duckduckgo.com/?q=" yandex "http://yandex.ru/yandsearch?text=" ) -- cgit v1.2.3-70-g09d2 From 02d75684f3ddd2dcd181c9265545d5639d09bd5a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 4 Jan 2015 01:40:25 +0100 Subject: Force using https in Yandex search engine --- plugins/web-search/web-search.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index b0a4a2926..572427b0b 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -10,7 +10,7 @@ function web_search() { bing "https://www.bing.com/search?q=" yahoo "https://search.yahoo.com/search?p=" duckduckgo "https://www.duckduckgo.com/?q=" - yandex "http://yandex.ru/yandsearch?text=" + yandex "https://yandex.ru/yandsearch?text=" ) # define the open command -- cgit v1.2.3-70-g09d2 From 0cc3afe27788e35d5f72236f41a7e4514c11491d Mon Sep 17 00:00:00 2001 From: Julien Pepy Date: Fri, 5 Dec 2014 09:57:59 +0100 Subject: Fix get command list for recent composer versions --- plugins/composer/composer.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/composer/composer.plugin.zsh b/plugins/composer/composer.plugin.zsh index 86f2ca4df..f75119c4a 100644 --- a/plugins/composer/composer.plugin.zsh +++ b/plugins/composer/composer.plugin.zsh @@ -7,7 +7,7 @@ # Composer basic command completion _composer_get_command_list () { - composer --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }' + composer --no-ansi | sed "1,/Available commands/d" | awk '/^\s*[a-z]+/ { print $1 }' } _composer_get_required_list () { -- cgit v1.2.3-70-g09d2 From 5f4e8e57da117b5fc2325ea411aafc66053b8570 Mon Sep 17 00:00:00 2001 From: Andrey Janzen Date: Fri, 26 Jul 2013 00:37:11 +0700 Subject: Allow completion for 'composer.phar', not only 'composer' Use $_comp_command1 for command list generation instead of 'composer': `$_comp_command1` contains the command written in the command line. This allows us to have a different composer name --- plugins/composer/composer.plugin.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/composer/composer.plugin.zsh b/plugins/composer/composer.plugin.zsh index f75119c4a..324bc64a0 100644 --- a/plugins/composer/composer.plugin.zsh +++ b/plugins/composer/composer.plugin.zsh @@ -7,11 +7,11 @@ # Composer basic command completion _composer_get_command_list () { - composer --no-ansi | sed "1,/Available commands/d" | awk '/^\s*[a-z]+/ { print $1 }' + $_comp_command1 --no-ansi | sed "1,/Available commands/d" | awk '/^\s*[a-z]+/ { print $1 }' } _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 () { @@ -35,6 +35,7 @@ _composer () { } compdef _composer composer +compdef _composer composer.phar # Aliases alias c='composer' -- cgit v1.2.3-70-g09d2 From ef220f0928269f3cdb613db3d3f9ba7775317109 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 17 Aug 2013 17:11:21 +0200 Subject: Add aliases for composer global --- plugins/composer/composer.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugins') diff --git a/plugins/composer/composer.plugin.zsh b/plugins/composer/composer.plugin.zsh index 324bc64a0..97207242a 100644 --- a/plugins/composer/composer.plugin.zsh +++ b/plugins/composer/composer.plugin.zsh @@ -41,9 +41,12 @@ compdef _composer composer.phar alias c='composer' alias csu='composer self-update' alias cu='composer update' +alias cr='composer require' alias ci='composer install' alias ccp='composer create-project' alias cdu='composer dump-autoload' +alias cgu='composer global update' +alias cgr='composer global require' # install composer in the current directory alias cget='curl -s https://getcomposer.org/installer | php' -- cgit v1.2.3-70-g09d2 From 6fb866183d84e53fa009853691e5c0bdd101820b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 4 Jan 2015 22:24:55 +0100 Subject: Remove composer.json file requirement This is because we can't be sure which arguments require a json file and which don't, so the `else' statement will always be difficult to check for correctness. --- plugins/composer/composer.plugin.zsh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'plugins') diff --git a/plugins/composer/composer.plugin.zsh b/plugins/composer/composer.plugin.zsh index 97207242a..7f70e3d72 100644 --- a/plugins/composer/composer.plugin.zsh +++ b/plugins/composer/composer.plugin.zsh @@ -20,18 +20,15 @@ _composer () { _arguments \ '1: :->command'\ '*: :->args' - if [ -f composer.json ]; then - case $state in - command) - compadd `_composer_get_command_list` - ;; - *) - compadd `_composer_get_required_list` - ;; - esac - else - compadd create-project init search selfupdate show - fi + + case $state in + command) + compadd $(_composer_get_command_list) + ;; + *) + compadd $(_composer_get_required_list) + ;; + esac } compdef _composer composer -- cgit v1.2.3-70-g09d2 From 4161aa4f9de45233bdee7073933498422a50d213 Mon Sep 17 00:00:00 2001 From: Brandon Sandrowicz Date: Tue, 20 May 2014 09:41:36 -0400 Subject: Fixing virtualenvwrapper plugin for Ubuntu (and Debian) Ubuntu and Debian store the system-installed virtualenvwrapper in /etc/bash_completion.d/virtualenvwrapper, so that it gets automatically sourced at startup in Bash. By not putting it somewhere in $PATH, they end up excluding others (e.g. Zsh) that might want to use that file. Oops! The virtualenvwrapper plugin should account for this so that Ubuntu (or Debian) users don't end up with this message: zsh virtualenvwrapper plugin: Cannot find virtualenvwrapper.sh. Please install with `pip install virtualenvwrapper`. even when they have a virtualenvwrapper installed to a known location. --- plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index 217ab0722..9a0616b72 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -1,12 +1,19 @@ virtualenvwrapper='virtualenvwrapper.sh' -if (( $+commands[$virtualenvwrapper] )); then +if (( $+commands[$virtualenvwrapper] )); then 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}. Please install with \`pip install virtualenvwrapper\`." + return +fi +if type workon 2>&1 >/dev/null; then if [[ "$WORKON_HOME" == "" ]]; then echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" else - if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then # Automatically activate Git projects's virtual environments based on the # directory name of the project. Virtual environment name can be overridden @@ -61,5 +68,5 @@ if (( $+commands[$virtualenvwrapper] )); then fi fi else - print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`." + print "zsh virtualenvwrapper plugin: shell function 'workon' not defined. Please check ${virtualenvwrapper}." >&2 fi -- cgit v1.2.3-70-g09d2 From b62911660d3743d3dfb0116f5b05aabd67a24a06 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 10 Feb 2015 12:20:24 +0100 Subject: Organize error checking in virtualenwrapper plugin --- .../virtualenvwrapper/virtualenvwrapper.plugin.zsh | 113 +++++++++++---------- 1 file changed, 58 insertions(+), 55 deletions(-) (limited to 'plugins') diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index 9a0616b72..0ad336917 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -6,67 +6,70 @@ 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}. Please install with \`pip install virtualenvwrapper\`." + 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 type workon 2>&1 >/dev/null; then - if [[ "$WORKON_HOME" == "" ]]; then - echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" - else - if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then - # Automatically activate Git projects's virtual environments based on the - # 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 - function workon_cwd { - if [ ! $WORKON_CWD ]; then - WORKON_CWD=1 - # Check if this is a Git repo - PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null` - if (( $? != 0 )); then - PROJECT_ROOT="." - fi - # Check for virtualenv name override - if [[ -f "$PROJECT_ROOT/.venv" ]]; then - ENV_NAME=`cat "$PROJECT_ROOT/.venv"` - elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then - ENV_NAME="$PROJECT_ROOT/.venv" - elif [[ "$PROJECT_ROOT" != "." ]]; then - ENV_NAME=`basename "$PROJECT_ROOT"` - else - ENV_NAME="" - fi - if [[ "$ENV_NAME" != "" ]]; then - # Activate the environment only if it is not already active - if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then - if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then - workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" - elif [[ -e "$ENV_NAME/bin/activate" ]]; then - source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" - fi - fi - elif [[ -n $CD_VIRTUAL_ENV && -n $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 - unset PROJECT_ROOT - unset WORKON_CWD - fi - } +if [[ "$WORKON_HOME" == "" ]]; then + print "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" >&2 + return +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 +if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then + # Automatically activate Git projects's virtual environments based on the + # 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 + function workon_cwd { + if [ ! $WORKON_CWD ]; then + WORKON_CWD=1 + # Check if this is a Git repo + PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null` + if (( $? != 0 )); then + PROJECT_ROOT="." + fi + # Check for virtualenv name override + if [[ -f "$PROJECT_ROOT/.venv" ]]; then + ENV_NAME=`cat "$PROJECT_ROOT/.venv"` + elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then + ENV_NAME="$PROJECT_ROOT/.venv" + elif [[ "$PROJECT_ROOT" != "." ]]; then + ENV_NAME=`basename "$PROJECT_ROOT"` else - set -A chpwd_functions workon_cwd + ENV_NAME="" + fi + if [[ "$ENV_NAME" != "" ]]; then + # Activate the environment only if it is not already active + if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then + if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then + workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" + elif [[ -e "$ENV_NAME/bin/activate" ]]; then + source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" + fi + fi + elif [[ -n $CD_VIRTUAL_ENV && -n $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 + 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 + else + set -A chpwd_functions workon_cwd fi -else - print "zsh virtualenvwrapper plugin: shell function 'workon' not defined. Please check ${virtualenvwrapper}." >&2 fi -- cgit v1.2.3-70-g09d2 From 732c7b8070a75ac5ad5384b4d22d19f499e8424f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 10 Feb 2015 12:24:05 +0100 Subject: Simplify adding workon_cwd to chpwd hook --- plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'plugins') diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index 0ad336917..5faa1a823 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -64,12 +64,7 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then # 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 - else - set -A chpwd_functions workon_cwd + if ! (( $chpwd_functions[(I)workon_cwd] )); then + chpwd_functions+=(workon_cwd) fi fi -- cgit v1.2.3-70-g09d2