1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 07:50:05 +08:00

Fix shell layer

This commit is contained in:
wsdjeg 2017-10-23 21:02:54 +08:00
parent 2d7572a35c
commit 7910b14e84

View File

@ -8,72 +8,77 @@
" "
function! SpaceVim#layers#shell#plugins() abort function! SpaceVim#layers#shell#plugins() abort
let plugins = [] let plugins = []
if has('nvim') if has('nvim')
call add(plugins,['Shougo/deol.nvim']) call add(plugins,['Shougo/deol.nvim'])
endif endif
call add(plugins,['Shougo/vimshell.vim', { 'on_cmd':['VimShell']}]) call add(plugins,['Shougo/vimshell.vim', { 'on_cmd':['VimShell']}])
return plugins return plugins
endfunction endfunction
let s:file = expand('<sfile>:~') let s:file = expand('<sfile>:~')
let s:lnum = expand('<slnum>') + 2 let s:lnum = expand('<slnum>') + 2
function! SpaceVim#layers#shell#config() abort function! SpaceVim#layers#shell#config() abort
call SpaceVim#mapping#space#def('nnoremap', ["'"], 'call call(' call SpaceVim#mapping#space#def('nnoremap', ["'"], 'call call('
\ . string(function('s:open_default_shell')) . ', [])', \ . string(function('s:open_default_shell')) . ', [])',
\ ['open shell', \ ['open shell',
\ [ \ [
\ "[SPC '] is to open or jump to default shell window", \ "[SPC '] is to open or jump to default shell window",
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ], 1) \ ], 1)
endfunction endfunction
let s:default_shell = 'terminal'
let s:default_position = 'top'
let s:default_height = 30
function! SpaceVim#layers#shell#set_variable(var) abort function! SpaceVim#layers#shell#set_variable(var) abort
let s:default_shell = get(a:var, 'default_shell', 'terminal') let s:default_shell = get(a:var, 'default_shell', 'terminal')
let s:default_position = get(a:var, 'default_position', 'top') let s:default_position = get(a:var, 'default_position', 'top')
let s:default_height = get(a:var, 'default_height', 30) let s:default_height = get(a:var, 'default_height', 30)
endfunction endfunction
let s:shell_win_nr = 0 let s:shell_win_nr = 0
function! s:open_default_shell() abort function! s:open_default_shell() abort
if s:shell_win_nr != 0 && getwinvar(s:shell_win_nr, '&buftype') ==# 'terminal' && &buftype !=# 'terminal' if s:shell_win_nr != 0 && getwinvar(s:shell_win_nr, '&buftype') ==# 'terminal' && &buftype !=# 'terminal'
exe s:shell_win_nr . 'wincmd w' exe s:shell_win_nr . 'wincmd w'
startinsert startinsert
return return
endif endif
if &buftype ==# 'terminal' if &buftype ==# 'terminal'
bwipeout! % bwipeout! %
return return
endif endif
let cmd = s:default_position ==# 'top' ? let cmd = s:default_position ==# 'top' ?
\ 'topleft split' : \ 'topleft split' :
\ s:default_position ==# 'bottom' ? \ s:default_position ==# 'bottom' ?
\ 'botright split' : \ 'botright split' :
\ s:default_position ==# 'right' ? \ s:default_position ==# 'right' ?
\ 'rightbelow vsplit' : 'leftabove vsplit' \ 'rightbelow vsplit' : 'leftabove vsplit'
exe cmd exe cmd
let lines = &lines * s:default_height / 100 let lines = &lines * s:default_height / 100
if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom') if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom')
exe 'resize ' . lines exe 'resize ' . lines
endif endif
if s:default_shell ==# 'terminal' if s:default_shell ==# 'terminal'
if exists(':terminal') if exists(':terminal')
if has('nvim') if has('nvim')
exe 'terminal' exe 'terminal'
else else
call term_start('bash', {'curwin' : 1, 'term_finish' : 'close'}) call term_start('bash', {'curwin' : 1, 'term_finish' : 'close'})
endif endif
let s:shell_win_nr = winnr() let s:shell_win_nr = winnr()
let w:shell_layer_win = 1 let w:shell_layer_win = 1
startinsert startinsert
else else
echo ':terminal is not supported in this version' echo ':terminal is not supported in this version'
endif
elseif s:default_shell ==# 'VimShell'
VimShell
imap <buffer> <C-d> exit<esc><Plug>(vimshell_enter)
endif endif
elseif s:default_shell ==# 'VimShell'
VimShell
imap <buffer> <C-d> exit<esc><Plug>(vimshell_enter)
endif
endfunction endfunction