Skip to content

Commit

Permalink
Merge pull request #1297 from chrisbra/mq
Browse files Browse the repository at this point in the history
Add mq status for hg repositories
  • Loading branch information
chrisbra committed Oct 26, 2016
2 parents 98fe4ea + 14ab47c commit 0ea4daa
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion autoload/airline/extensions/branch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,18 @@ endfunction

function! s:get_hg_branch()
if s:has_lawrencium
return lawrencium#statusline()
let stl=lawrencium#statusline()
if !empty(stl) && has('job')
call s:get_mq_async('hg qtop', expand('%:p'))
endif
if exists("s:mq") && !empty(s:mq)
if stl is# 'default'
" Shorten default a bit
let stl='def'
endif
let stl.=' ['.s:mq.']'
endif
return stl
endif
return ''
endfunction
Expand Down Expand Up @@ -154,6 +165,44 @@ if s:has_async
\ 'close_cb': function('s:on_exit', options)})
let s:jobs[a:file] = id
endfu

function! s:on_exit_mq(channel) dict abort
if !empty(self.buf)
if self.buf is# 'no patches applied' ||
\ self.buf =~# "unknown command 'qtop'"
let self.buf = ''
elseif exists("s:mq") && s:mq isnot# self.buf
" make sure, statusline is updated
unlet! b:airline_head
endif
let s:mq = self.buf
endif
if has_key(s:jobs, self.file)
call remove(s:jobs, self.file)
endif
endfunction

function! s:get_mq_async(cmd, file)
if g:airline#util#is_windows && &shell =~ 'cmd'
let cmd = a:cmd. shellescape(a:file)
else
let cmd = ['sh', '-c', a:cmd]
endif

let options = {'cmd': a:cmd, 'buf': '', 'file': a:file}
if has_key(s:jobs, a:file)
if job_status(get(s:jobs, a:file)) == 'run'
return
elseif has_key(s:jobs, a:file)
call remove(s:jobs, a:file)
endif
endif
let id = job_start(cmd, {
\ 'err_io': 'out',
\ 'out_cb': function('s:on_stdout', options),
\ 'close_cb': function('s:on_exit_mq', options)})
let s:jobs[a:file] = id
endfu
endif

function! airline#extensions#branch#head()
Expand Down

0 comments on commit 0ea4daa

Please sign in to comment.