From 623d162f2b22dcf2f2e5ee2c8799838f5e70ec2a Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 22 Nov 2014 01:47:04 -0800 Subject: [PATCH] [bobthefish] More virtualenv tweaks * Inline a one-line method that's called one place * Make sure __bobthecow_virtualenv_python_version doesn't fail if python isn't a symlink. * Add a visual segment indicator after python version glyph. --- fish_prompt.fish | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index eeec09c..ccbd524 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -310,25 +310,27 @@ function __bobthefish_prompt_dir -d 'Display a shortened form of the current dir end function __bobthefish_virtualenv_python_version -d 'Get current python version' - switch (readlink (which python)) + set -l python_version (readlink (which python)) + switch "$python_version" case python2 echo $__bobthefish_superscript_glyph[2] case python3 echo $__bobthefish_superscript_glyph[3] case pypy echo $__bobthefish_pypy_glyph - end -end - -function __bobthefish_virtualenv -d 'Get the current virtualenv' - echo $__bobthefish_virtualenv_glyph(__bobthefish_virtualenv_python_version) (basename "$VIRTUAL_ENV") + end end function __bobthefish_prompt_virtualfish -d "Display activated virtual environment (only for virtualfish, virtualenv's activate.fish changes prompt by itself)" set -q VIRTUAL_ENV; or return + set -l version_glyph (__bobthefish_virtualenv_python_version) + if test "$version_glyph" + __bobthefish_start_segment $__bobthefish_med_blue $__bobthefish_lt_grey + echo -n -s $__bobthefish_virtualenv_glyph $version_glyph + end __bobthefish_start_segment $__bobthefish_med_blue $__bobthefish_lt_grey set_color $__bobthefish_lt_grey --bold - echo -n -s (__bobthefish_virtualenv) ' ' + echo -n -s (basename "$VIRTUAL_ENV") ' ' set_color normal end