Skip to content

Instantly share code, notes, and snippets.

@gmalysa
Created January 29, 2015 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmalysa/3c4d87568ef995866f2d to your computer and use it in GitHub Desktop.
Save gmalysa/3c4d87568ef995866f2d to your computer and use it in GitHub Desktop.
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
echo a:cmdline
let expanded_cmdline = a:cmdline
for part in split(a:cmdline, ' ')
if part[0] =~ '\v[%#<]'
let expanded_part = fnameescape(expand(part))
let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
endif
endfor
let shellwin=bufwinnr('ShellResults')
let taskwin=bufwinnr('TaskList')
if shellwin == -1
if taskwin == -1
set splitright
vsplit ShellResults
else
exec taskwin . ' :wincmd w'
split ShellResults
endif
setlocal buftype=nofile noswapfile nowrap
else
exec shellwin . ' :wincmd w'
normal! ggdG
endif
call setline(1, '$ ' . a:cmdline)
let result=system(expanded_cmdline)
call append(1, split(result, '\v\n'))
endfunction
function! s:Tasklist()
let cmdline='/home/greg/scripts/fstr.sh "@todo"'
let taskwin=bufwinnr('TaskList')
let shellwin=bufwinnr('ShellResults')
if taskwin == -1
if shellwin == -1
set splitright
vsplit TaskList
else
exec shellwin . ' :wincmd w'
split TaskList
endif
setlocal buftype=nofile noswapfile nowrap
else
exec taskwin . ' :wincmd w'
normal! ggdG
endif
call setline(1, 'Current Tasks:')
let tasks=system(cmdline)
call append(1, split(tasks, '\v\n'))
endfunction
command! -complete=shellcmd -nargs=0 Tasks call s:Tasklist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment