From 4878fab120117529b32f944b56b517127b2b8b0c Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Fri, 21 Nov 2014 23:39:39 +0800 Subject: [PATCH] Add a virtualenv fallback when vim-virtualenv is not presented --- autoload/airline/extensions.vim | 2 +- autoload/airline/extensions/virtualenv.vim | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 1738f62..66a1c34 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -178,7 +178,7 @@ function! airline#extensions#load() call airline#extensions#bufferline#init(s:ext) endif - if get(g:, 'virtualenv_loaded', 0) && get(g:, 'airline#extensions#virtualenv#enabled', 1) + if isdirectory($VIRTUAL_ENV) && get(g:, 'airline#extensions#virtualenv#enabled', 1) call airline#extensions#virtualenv#init(s:ext) endif diff --git a/autoload/airline/extensions/virtualenv.vim b/autoload/airline/extensions/virtualenv.vim index f070c47..27f847e 100644 --- a/autoload/airline/extensions/virtualenv.vim +++ b/autoload/airline/extensions/virtualenv.vim @@ -1,7 +1,7 @@ " MIT License. Copyright (c) 2013-2014 Bailey Ling. " vim: et ts=2 sts=2 sw=2 -if !get(g:, 'virtualenv_loaded', 0) +if !isdirectory($VIRTUAL_ENV) finish endif @@ -13,8 +13,13 @@ endfunction function! airline#extensions#virtualenv#apply(...) if &filetype =~ "python" + if get(g:, 'virtualenv_loaded', 0) + let statusline = virtualenv#statusline() + else + let statusline = fnamemodify($VIRTUAL_ENV, ':t') + endif call airline#extensions#append_to_section('x', - \ s:spc.g:airline_right_alt_sep.s:spc.'%{virtualenv#statusline()}') + \ s:spc.g:airline_right_alt_sep.s:spc.statusline) endif endfunction