mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-22 04:10:07 +00:00
Add new pyenv segment to show active python version
This commit provides a new segment `pyenv` to show current python environment. This prompt can be used in place of `virtualenv` segment. However, it is targeted at users of [pyenv](https://github.com/yyuu/pyenv) and not meant to replace the `virtualenv` segment. The prompt works by parsing output of `pyenv version` and displaying the first word of the output as segment text. The design (color etc.) is same as the `virtualenv` segment including the icon. The segment would need to be revisited if `pyenv version` changes its output format. Tested on my personal machines (Mac OSX 10.11.4 and Ubuntu 15.04).
This commit is contained in:
parent
41888bf2a9
commit
99429ab268
2 changed files with 17 additions and 0 deletions
|
@ -116,6 +116,7 @@ The segments that are currently available are:
|
|||
* **Python Segments:**
|
||||
* `virtualenv` - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/).
|
||||
* [`anaconda`](#anaconda) - Your active [Anaconda](https://www.continuum.io/why-anaconda) environment.
|
||||
* `pyenv` - Your active python version as reported by the first word of [`pyenv version`](https://github.com/yyuu/pyenv). Note that the segment is not displayed if that word is _system_ i.e. the segment is inactive if you are using system python.
|
||||
* **Ruby Segments:**
|
||||
* [`chruby`](#chruby) - Ruby environment information using `chruby` (if one is active).
|
||||
* [`rbenv`](#rbenv) - Ruby environment information using `rbenv` (if one is active).
|
||||
|
|
|
@ -935,6 +935,22 @@ prompt_virtualenv() {
|
|||
fi
|
||||
}
|
||||
|
||||
# pyenv: current active python version (with restrictions)
|
||||
# More information on pyenv (Python version manager like rbenv and rvm):
|
||||
# https://github.com/yyuu/pyenv
|
||||
# the prompt parses output of pyenv version and only displays the first word
|
||||
prompt_pyenv() {
|
||||
local pyenv_version="$(pyenv version 2>/dev/null)"
|
||||
pyenv_version="${pyenv_version%% *}"
|
||||
# XXX: The following should return the same as above.
|
||||
# This reads better for devs familiar with sed/awk/grep/cut utilities
|
||||
# Using shell expansion/substitution may hamper future maintainability
|
||||
#local pyenv_version="$(pyenv version 2>/dev/null | head -n1 | cut -d' ' -f1)"
|
||||
if [[ -n "$pyenv_version" && "$pyenv_version" != "system" ]]; then
|
||||
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version" 'PYTHON_ICON'
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################
|
||||
# Prompt processing and drawing
|
||||
################################################################
|
||||
|
|
Loading…
Reference in a new issue