Shell command

This commit is contained in:
ManjaroOne666 2018-03-29 21:41:18 +01:00
parent afd58df252
commit 5bd71dd921
1 changed files with 57 additions and 0 deletions

View File

@ -80,6 +80,63 @@ function! LinterStatus() abort "{{{
endfunction
"}}}
" Shell command
" based on
" http://vim.wikia.com/wiki/VimTip1599
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
let g:shell_scratch_buffer_nr = -1
function! s:RunShellCommand(cmdline) abort
"{{{
let l:expanded_cmdline = a:cmdline
for l:part in split(a:cmdline, ' ')
if l:part[0] =~ '\v[%#<]'
let l:expanded_part = fnameescape(expand(l:part))
let l:expanded_cmdline = substitute(l:expanded_cmdline, l:part, l:expanded_part, '')
endif
endfor
if g:shell_scratch_buffer_nr > -1
let l:win_nr = bufwinnr(g:shell_scratch_buffer_nr)
if l:win_nr < 0
execute 'bdelete' g:shell_scratch_buffer_nr
top new
let g:shell_scratch_buffer_nr = bufnr('%')
else
execute l:win_nr. ' wincmd w'
setlocal modifiable
%delete _
endif
else
top new
let g:shell_scratch_buffer_nr = bufnr('%')
endif
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
nnoremap <buffer> q :bdelete<CR>
augroup ResetShellBufferNr
autocmd! * <buffer>
autocmd BufUnload <buffer> let g:shell_scratch_buffer_nr = -1
augroup END
" call setline(1, 'You entered: ' . a:cmdline)
" call setline(2, 'Expanded Form: ' .l:expanded_cmdline)
" call setline(3,substitute(getline(2),'.','=','g'))
execute '$read !'. l:expanded_cmdline
1
setlocal nomodifiable
if !exists('b:shell_line_count')
let b:shell_line_count = line('$')
if b:shell_line_count > 25
let b:shell_line_count = 20
endif
execute 'resize' b:shell_line_count + 1
endif
wincmd p
endfunction
"}}}