1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2025-07-01 18:39:26 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
e3696d2c28 Automatic virtualenv activaiion and deactivation, virtualenv non lazy
mode
2013-12-20 04:09:45 -05:00
15 changed files with 132 additions and 78 deletions

View File

@ -9,7 +9,8 @@ Installation
------------ ------------
Prezto will work with any recent release of Zsh, but the minimum recommended Prezto will work with any recent release of Zsh, but the minimum recommended
version is 4.3.11. version is 4.3.11. Unfortunately, [Cygwin][9] is not supported due to
non-standard core utilities.
1. Launch Zsh: 1. Launch Zsh:
@ -36,7 +37,7 @@ version is 4.3.11.
### Troubleshooting ### Troubleshooting
If you are not able to find certain commands after switching to *Prezto*, If you are not able to find certain commands after switching to *Prezto*,
modify the `PATH` variable in *~/.zprofile* then open a new Zsh terminal modify the `PATH` variable in *~/.zshenv* then open a new Zsh terminal
window or tab. window or tab.
Updating Updating
@ -85,8 +86,7 @@ License
(The MIT License) (The MIT License)
Copyright (c) 2009-2011 Robby Russell and contributors. Copyright (c) 2009-2014 Sorin Ionescu and contributors.
Copyright (c) 2011-2014 Sorin Ionescu and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@ -114,4 +114,5 @@ SOFTWARE.
[6]: http://gitref.org [6]: http://gitref.org
[7]: http://www.bash2zsh.com/zsh_refcard/refcard.pdf [7]: http://www.bash2zsh.com/zsh_refcard/refcard.pdf
[8]: http://grml.org/zsh/zsh-lovers.html [8]: http://grml.org/zsh/zsh-lovers.html
[9]: http://www.cygwin.com

View File

@ -25,7 +25,7 @@ unset min_zsh_version
function pmodload { function pmodload {
local -a pmodules local -a pmodules
local pmodule local pmodule
local pfunction_glob='^([_.]*|prompt_*_setup|README*)(-.N:t)' local pfunction_glob='^([_.]*|prompt_*_setup|README*)(.N:t)'
# $argv is overridden in the anonymous function. # $argv is overridden in the anonymous function.
pmodules=("$argv[@]") pmodules=("$argv[@]")

View File

@ -107,39 +107,30 @@ function editor-info {
} }
zle -N editor-info zle -N editor-info
# Updates editor information when the keymap changes. # Ensures that $terminfo values are valid and updates editor information when
function zle-keymap-select { # the keymap changes.
function zle-keymap-select zle-line-init zle-line-finish {
# The terminal must be in application mode when ZLE is active for $terminfo
# values to be valid.
if (( $+terminfo[smkx] && $+terminfo[rmkx] )); then
case "$0" in
(zle-line-init)
# Enable terminal application mode.
echoti smkx
;;
(zle-line-finish)
# Disable terminal application mode.
echoti rmkx
;;
esac
fi
# Update editor information.
zle editor-info zle editor-info
} }
zle -N zle-keymap-select zle -N zle-keymap-select
# Enables terminal application mode and updates editor information.
function zle-line-init {
# The terminal must be in application mode when ZLE is active for $terminfo
# values to be valid.
if (( $+terminfo[smkx] )); then
# Enable terminal application mode.
echoti smkx
fi
# Update editor information.
zle editor-info
}
zle -N zle-line-init
# Disables terminal application mode and updates editor information.
function zle-line-finish {
# The terminal must be in application mode when ZLE is active for $terminfo
# values to be valid.
if (( $+terminfo[rmkx] )); then
# Disable terminal application mode.
echoti rmkx
fi
# Update editor information.
zle editor-info
}
zle -N zle-line-finish zle -N zle-line-finish
zle -N zle-line-init
# Toggles emacs overwrite mode and updates editor information. # Toggles emacs overwrite mode and updates editor information.
function overwrite-mode { function overwrite-mode {

View File

@ -12,7 +12,7 @@ fi
# Set the default paths to gpg-agent files. # Set the default paths to gpg-agent files.
_gpg_agent_conf="$HOME/.gnupg/gpg-agent.conf" _gpg_agent_conf="$HOME/.gnupg/gpg-agent.conf"
_gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env" _gpg_agent_env="$TMPDIR/gpg-agent.env"
# Start gpg-agent if not started. # Start gpg-agent if not started.
if ! ps -U "$USER" -o ucomm | grep -q gpg-agent; then if ! ps -U "$USER" -o ucomm | grep -q gpg-agent; then

View File

@ -6,7 +6,7 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # Sorin Ionescu <sorin.ionescu@gmail.com>
# #
local tmp="${TMPDIR:-/tmp}/pacman-disowned-$UID-$$" local tmp="$TMPDIR/pacman-disowned-$UID-$$"
local db="$tmp/db" local db="$tmp/db"
local fs="$tmp/fs" local fs="$tmp/fs"

View File

@ -9,13 +9,10 @@
pacman --query --explicit --info \ pacman --query --explicit --info \
| awk ' | awk '
BEGIN { BEGIN {
FS=" : " FS=":"
} }
/^Name/ { /^Name/ {
printf "\033[0;01m" $2 "\033[0m" print $2
}
/^Version/ {
print " \033[1;32m" $2 "\033[0m"
} }
/^Description/ { /^Description/ {
print $2 print $2

View File

@ -27,9 +27,6 @@ if (( $+commands[$_pacman_frontend] )); then
if [[ -s "${0:h}/${_pacman_frontend}.zsh" ]]; then if [[ -s "${0:h}/${_pacman_frontend}.zsh" ]]; then
source "${0:h}/${_pacman_frontend}.zsh" source "${0:h}/${_pacman_frontend}.zsh"
fi fi
else
_pacman_frontend='pacman'
_pacman_sudo='sudo '
fi fi
# #
@ -37,49 +34,49 @@ fi
# #
# Pacman. # Pacman.
alias pac="${_pacman_frontend}" alias pac='pacman'
# Installs packages from repositories. # Installs packages from repositories.
alias paci="${_pacman_sudo}${_pacman_frontend} --sync" alias paci='sudo pacman --sync'
# Installs packages from files. # Installs packages from files.
alias pacI="${_pacman_sudo}${_pacman_frontend} --upgrade" alias pacI='sudo pacman --upgrade'
# Removes packages and unneeded dependencies. # Removes packages and unneeded dependencies.
alias pacx="${_pacman_sudo}${_pacman_frontend} --remove" alias pacx='sudo pacman --remove'
# Removes packages, their configuration, and unneeded dependencies. # Removes packages, their configuration, and unneeded dependencies.
alias pacX="${_pacman_sudo}${_pacman_frontend} --remove --nosave --recursive" alias pacX='sudo pacman --remove --nosave --recursive'
# Displays information about a package from the repositories. # Displays information about a package from the repositories.
alias pacq="${_pacman_frontend} --sync --info" alias pacq='pacman --sync --info'
# Displays information about a package from the local database. # Displays information about a package from the local database.
alias pacQ="${_pacman_frontend} --query --info" alias pacQ='pacman --query --info'
# Searches for packages in the repositories. # Searches for packages in the repositories.
alias pacs="${_pacman_frontend} --sync --search" alias pacs='pacman --sync --search'
# Searches for packages in the local database. # Searches for packages in the local database.
alias pacS="${_pacman_frontend} --query --search" alias pacS='pacman --query --search'
# Lists orphan packages. # Lists orphan packages.
alias pacman-list-orphans="${_pacman_frontend} --query --deps --unrequired" alias pacman-list-orphans='sudo pacman --query --deps --unrequired'
# Removes orphan packages. # Removes orphan packages.
alias pacman-remove-orphans="${_pacman_sudo}${_pacman_frontend} --remove --recursive \$(${_pacman_frontend} --quiet --query --deps --unrequired)" alias pacman-remove-orphans='sudo pacman --remove --recursive $(pacman --quiet --query --deps --unrequired)'
# Synchronizes the local package and Arch Build System databases against the # Synchronizes the local package and Arch Build System databases against the
# repositories. # repositories.
if (( $+commands[abs] )); then if (( $+commands[abs] )); then
alias pacu="${_pacman_sudo}${_pacman_frontend} --sync --refresh && ${_pacman_sudo}abs" alias pacu='sudo pacman --sync --refresh && sudo abs'
else else
alias pacu="${_pacman_sudo}${_pacman_frontend} --sync --refresh" alias pacu='sudo pacman --sync --refresh'
fi fi
# Synchronizes the local package database against the repositories then # Synchronizes the local package database against the repositories then
# upgrades outdated packages. # upgrades outdated packages.
alias pacU="${_pacman_sudo}${_pacman_frontend} --sync --refresh --sysupgrade" alias pacU='sudo pacman --sync --refresh --sysupgrade'
unset _pacman_{frontend,sudo} unset _pacman_frontend

View File

@ -11,9 +11,9 @@
# Disable color. # Disable color.
if ! zstyle -t ':prezto:module:pacman:yaourt' color; then if ! zstyle -t ':prezto:module:pacman:yaourt' color; then
alias pacman='yaourt --nocolor' alias pacman='pacman --nocolor'
fi fi
# Manages .pac* files. # Manages .pac* files.
alias pacc='yaourt -C' alias pacc='pacman -C'

View File

@ -61,6 +61,29 @@ system site-packages directory.
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages' export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
### Settings
#### Lazy loading
By default, virtualenvwrapper is loaded in lazy mode. This behaviour can be disabled adding the following line to *~/.zpreztorc*:
zstyle ':prezto:module:python' lazy_venv 'no'
#### Automatic virtualenv initialization
To enable autoenv, add the following line to *~/.zpreztorc*:
zstyle ':prezto:module:python' autoenv 'yes'
If a virtualenv is active, and was not activated by autoenv, then autoenv does nothing.
Otherwise, autoenv activated or deactivates a virtual environment whenever a directory is changed; based on the following priority:
1. Name specified in a file named *.venv* in the cwd.
2. *.venv* file in git root. If folder is inside git repository.
3. Name of git root folder.
4. No virtualenv.
Aliases Aliases
------- -------

View File

@ -31,17 +31,66 @@ if (( ! $+commands[python] && ! $+commands[pyenv] )); then
return 1 return 1
fi fi
local venv_script=virtualenvwrapper
if zstyle -T ':prezto:module:python' lazy_venv; then
venv_script+=_lazy
fi
# Load virtualenvwrapper into the shell session. # Load virtualenvwrapper into the shell session.
if (( $+commands[virtualenvwrapper_lazy.sh] )); then if (( $+commands[$venv_script.sh] )); then
# Set the directory where virtual environments are stored. # Set the directory where virtual environments are stored.
export WORKON_HOME="$HOME/.virtualenvs" export WORKON_HOME="$HOME/.virtualenvs"
# Disable the virtualenv prompt. # Disable the virtualenv prompt.
VIRTUAL_ENV_DISABLE_PROMPT=1 VIRTUAL_ENV_DISABLE_PROMPT=1
source "$commands[virtualenvwrapper_lazy.sh]" source "$commands[$venv_script.sh]"
fi fi
function autoenv {
#Don't run in shell scripts etc.
if [[ $ZSH_SUBSHELL -ne 0 ]]; then
return
fi
#Don't run if currently in virtual env not set by autoenv
if (( ($+VIRTUAL_ENV) && !($+AUTOENV) )); then
return
fi
local name=""
if [[ -f .venv ]]; then
#.venv file in current dir gets highest priority
name=$(<.venv)
elif is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
local gitroot="$(git rev-parse --show-toplevel 2> /dev/null)"
if [ -f "$gitroot/.venv" ]; then
#If there is a .venv file in gitroot
name=$(<$gitroot/.venv)
else
#Else use the name of the folder as venv name
name=$gitroot:t
fi
fi
local venv_name="$VIRTUAL_ENV:t"
if [[ $name != $venv_name ]]; then
if [[ -z $name ]]; then
deactivate && unset AUTOENV
return
fi
if [[ -d "$WORKON_HOME/$name" ]]; then
workon $name && export AUTOENV=1
return
fi
fi
}
if zstyle -T ':prezto:module:python' autoenv; then
add-zsh-hook chpwd autoenv
fi
# #
# Aliases # Aliases
# #

View File

@ -43,14 +43,14 @@ alias rb='ruby'
# Bundler # Bundler
if (( $+commands[bundle] )); then if (( $+commands[bundle] )); then
alias rbb='bundle' alias rbb='bundle'
alias rbbe='bundle exec' alias rbbe='rbb exec'
alias rbbi='bundle install --path vendor/bundle' alias rbbi='rbb install'
alias rbbl='bundle list' alias rbbl='rbb list'
alias rbbo='bundle open' alias rbbo='rbb open'
alias rbbp='bundle package' alias rbbp='rbb package'
alias rbbu='bundle update' alias rbbu='rbb update'
alias rbbI='rbbi \ alias rbbI='rbbi \
&& bundle package \ && rbb package \
&& print .bundle >>! .gitignore \ && print .bundle >>! .gitignore \
&& print vendor/assets >>! .gitignore \ && print vendor/assets >>! .gitignore \
&& print vendor/bundle >>! .gitignore \ && print vendor/bundle >>! .gitignore \

View File

@ -14,10 +14,10 @@ fi
_ssh_dir="$HOME/.ssh" _ssh_dir="$HOME/.ssh"
# Set the path to the environment file if not set by another module. # Set the path to the environment file if not set by another module.
_ssh_agent_env="${_ssh_agent_env:-${TMPDIR:-/tmp}/ssh-agent.env}" _ssh_agent_env="${_ssh_agent_env:-$TMPDIR/ssh-agent.env}"
# Set the path to the persistent authentication socket. # Set the path to the persistent authentication socket.
_ssh_agent_sock="${TMPDIR:-/tmp}/ssh-agent.sock" _ssh_agent_sock="$TMPDIR/ssh-agent.sock"
# Start ssh-agent if not started. # Start ssh-agent if not started.
if [[ ! -S "$SSH_AUTH_SOCK" ]]; then if [[ ! -S "$SSH_AUTH_SOCK" ]]; then

View File

@ -6,7 +6,7 @@
# #
# Return if requirements are not found. # Return if requirements are not found.
if [[ "$TERM" == (dumb|linux|*bsd*) ]]; then if [[ "$TERM" == 'dumb' ]]; then
return 1 return 1
fi fi

View File

@ -104,10 +104,6 @@ alias sl='ls' # I often screw this up.
# Mac OS X Everywhere # Mac OS X Everywhere
if [[ "$OSTYPE" == darwin* ]]; then if [[ "$OSTYPE" == darwin* ]]; then
alias o='open' alias o='open'
elif [[ "$OSTYPE" == cygwin* ]]; then
alias o='cygstart'
alias pbcopy='tee > /dev/clipboard'
alias pbpaste='cat /dev/clipboard'
else else
alias o='xdg-open' alias o='xdg-open'

View File

@ -6,7 +6,7 @@
# #
# Ensure that a non-login, non-interactive shell has a defined environment. # Ensure that a non-login, non-interactive shell has a defined environment.
if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then if [[ "$SHLVL" -eq 1 && ! -o LOGIN ]]; then
source "${ZDOTDIR:-$HOME}/.zprofile" source "${ZDOTDIR:-$HOME}/.zprofile"
fi fi