Browse Source

[Fix #248] Replace virtualenv_info with python-info

Conflicts:
	modules/python/README.md
master
Sorin Ionescu 12 years ago
parent
commit
98c545a102
  1. 15
      modules/prompt/functions/prompt_steeef_setup
  2. 17
      modules/python/README.md
  3. 21
      modules/python/functions/python-info
  4. 2
      modules/python/init.zsh

15
modules/prompt/functions/prompt_steeef_setup

@ -12,12 +12,6 @@ @@ -12,12 +12,6 @@
# http://i.imgur.com/HyRvv.png
#
function virtualenv_info {
if [[ -n "$VIRTUAL_ENV" ]]; then
print "(${VIRTUAL_ENV:t}) "
fi
}
function prompt_steeef_precmd {
# Check for untracked files or updated submodules since vcs_info does not.
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
@ -29,6 +23,10 @@ function prompt_steeef_precmd { @@ -29,6 +23,10 @@ function prompt_steeef_precmd {
zstyle ':vcs_info:*:prompt:*' formats "${branch_format}"
vcs_info 'prompt'
if (( $+functions[python-info] )); then
python-info
fi
}
function prompt_steeef_setup {
@ -83,10 +81,13 @@ function prompt_steeef_setup { @@ -83,10 +81,13 @@ function prompt_steeef_setup {
zstyle ':vcs_info:*:prompt:*' formats "${branch_format}"
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
# Set python-info parameters.
zstyle ':omz:module:python' virtualenv '(%v)'
# Define prompts.
PROMPT="
${_prompt_steeef_colors[3]}%n%f at ${_prompt_steeef_colors[2]}%m%f in ${_prompt_steeef_colors[5]}%~%f "'${vcs_info_msg_0_}'"
"'$(virtualenv_info)'"$ "
"'$python_info[virtualenv]'"$ "
}
prompt_steeef_setup "$@"

17
modules/python/README.md

@ -44,6 +44,17 @@ convenient shell functions to create, switch, and manage them. @@ -44,6 +44,17 @@ convenient shell functions to create, switch, and manage them.
Install virtualenvwrapper and set [`$WORKON_HOME`][4] to the path where virtual
environments will be stored.
### Theming
To display the name of the current virtual enviroment in a prompt, define the
following style in the `prompt_theme_setup` function.
# %v - virtualenv name.
zstyle ':omz:module:python' virtualenv 'virtualenv:%v'
Then add `$python_info[virtualenv]` to `$PROMPT` or `$RPROMPT` and call
`python-info` in the `prompt_theme_preexec` hook function.
Aliases
-------
@ -59,6 +70,12 @@ Aliases @@ -59,6 +70,12 @@ Aliases
- `pyzu` updates itself to the latest version.
- `pyzx` uninstalls Python versions.
Functions
---------
- `python-info` exposes information about the Python environment via the
`$python_info` associative array.
Authors
-------

21
modules/python/functions/python-info

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
#
# Displays Python information.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local virtualenv_format
local virtualenv_formatted
# Clean up previous $python_info.
unset python_info
typeset -gA python_info
# Format virtualenv.
if [[ -n "$VIRTUAL_ENV" ]]; then
zstyle -s ':omz:module:python' virtualenv 'virtualenv_format'
zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}"
python_info[virtualenv]="$virtualenv_formatted"
fi

2
modules/python/init.zsh

@ -24,6 +24,8 @@ fi @@ -24,6 +24,8 @@ fi
# Load virtualenvwrapper into the shell session.
if [[ -n "$WORKON_HOME" ]] && (( $+commands[virtualenvwrapper.sh] )); then
# Disable the virtualenv prompt.
VIRTUAL_ENV_DISABLE_PROMPT=1
source "$commands[virtualenvwrapper.sh]"
fi

Loading…
Cancel
Save