-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmus.vim
More file actions
42 lines (38 loc) · 1.11 KB
/
cmus.vim
File metadata and controls
42 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
if !executable('cmus')
finish
endif
func s:open_new_cmus_buffer(mods, ...) abort
if has('nvim')
execute a:mods 'new term://cmus'
else
let args = get(a:, 1, '')
execute a:mods 'ter ++close' args 'cmus'
endif
endfunc
func s:cmus(mods) abort
" We add the [:-2] to strip the new line character at the end
let pid = system('pgrep cmus')[:-2]
if v:shell_error
" cmus isn't running
return s:open_new_cmus_buffer(a:mods)
endif
try
if has('nvim')
execute a:mods 'sb term://*/' . pid . ':cmus'
else
execute a:mods 'sb !cmus'
endif
catch /^Vim\%((\a\+)\)\=:E94:/
echoerr "cmus isn't running in this " . (has('nvim') ? 'Neovim' : 'Vim') . ' instance'
endtry
endfunc
let s:nargs = has('nvim') ? '' : '-nargs=*'
execute 'command -bar' s:nargs 'Cmus call <SID>cmus("<mods>")'
if executable('cmus-remote')
nnoremap <leader>c <Cmd>call system('cmus-remote -u')<cr>
nnoremap <leader>C <Cmd>call system('cmus-remote -C toggle\ continue')<cr>
if !has('nvim')
tnoremap <C-W><leader>c <Cmd>call system('cmus-remote -u')<cr>
tnoremap <C-W><leader>C <Cmd>call system('cmus-remote -C toggle\ continue')<cr>
endif
endif