mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 21:00:03 +08:00
Add gtm support (#2512)
This commit is contained in:
parent
771177f4d9
commit
fa4d25a2eb
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,3 +30,4 @@ cscope.po.out
|
||||
build/
|
||||
.coverage.covimerage
|
||||
*.swp
|
||||
.gtm/
|
||||
|
@ -10,6 +10,8 @@ scriptencoding utf-8
|
||||
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
|
||||
let s:enable_gtm_status = 0
|
||||
|
||||
function! SpaceVim#layers#VersionControl#plugins() abort
|
||||
let plugins = []
|
||||
call add(plugins, ['mhinz/vim-signify', {'merged' : 0}])
|
||||
@ -31,28 +33,76 @@ function! SpaceVim#layers#VersionControl#config() abort
|
||||
\ 'version control info', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'm', 'h'], 'call SpaceVim#layers#core#statusline#toggle_section("hunks")',
|
||||
\ 'toggle the hunks summary', 1)
|
||||
let g:gtm_plugin_status_enabled = s:enable_gtm_status
|
||||
if s:enable_gtm_status
|
||||
augroup gtm_plugin
|
||||
autocmd!
|
||||
autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI * silent call s:record()
|
||||
augroup END
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#VersionControl#set_variable(var) abort
|
||||
let s:enable_gtm_status = get(a:var,
|
||||
\ 'enable_gtm_status',
|
||||
\ s:enable_gtm_status)
|
||||
endfunction
|
||||
|
||||
" master
|
||||
function! s:git_branch() abort
|
||||
if exists('g:loaded_fugitive')
|
||||
try
|
||||
let l:head = fugitive#head()
|
||||
if empty(l:head)
|
||||
call fugitive#detect(getcwd())
|
||||
let l:head = fugitive#head()
|
||||
endif
|
||||
if g:spacevim_statusline_unicode_symbols == 1
|
||||
return empty(l:head) ? '' : ' '.l:head . ' '
|
||||
else
|
||||
return empty(l:head) ? '' : ' '.l:head . ' '
|
||||
endif
|
||||
if empty(l:head)
|
||||
call fugitive#detect(getcwd())
|
||||
let l:head = fugitive#head()
|
||||
endif
|
||||
if g:spacevim_statusline_unicode_symbols == 1
|
||||
return empty(l:head) ? '' : ' '.l:head . s:gtm_status()
|
||||
else
|
||||
return empty(l:head) ? '' : ' '.l:head . s:gtm_status()
|
||||
endif
|
||||
catch
|
||||
endtry
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:gtm_status() abort
|
||||
if s:enable_gtm_status
|
||||
let status = s:gtm_statusline()
|
||||
return empty(status) ? '' : ' (' . status . ') '
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:last_update = 0
|
||||
let s:last_file = ''
|
||||
let s:update_interval = 30
|
||||
let s:gtm_plugin_status = ''
|
||||
|
||||
function! s:record()
|
||||
let fpath = expand('%:p')
|
||||
" record if file path has changed or last update is greater than update_interval
|
||||
if (s:last_file != fpath || localtime() - s:last_update > s:update_interval) && filereadable(fpath)
|
||||
let s:cmd = (s:enable_gtm_status == 1 ? 'gtm record --status' : 'gtm record')
|
||||
let output=system(s:cmd . ' ' . shellescape(fpath))
|
||||
if v:shell_error
|
||||
echoerr s:no_gtm_err
|
||||
else
|
||||
let s:gtm_plugin_status = (s:enable_gtm_status ? substitute(output, '\n\+$', '', '') : '')
|
||||
endif
|
||||
let s:last_update = localtime()
|
||||
let s:last_file = fpath
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:gtm_statusline() abort
|
||||
return s:gtm_plugin_status
|
||||
endfunction
|
||||
|
||||
" +0 ~0 -0
|
||||
function! s:hunks() abort
|
||||
let hunks = [0,0,0]
|
||||
|
@ -10,6 +10,7 @@ lang: cn
|
||||
|
||||
- [模块介绍](#模块介绍)
|
||||
- [启用模块](#启用模块)
|
||||
- [模块选项](#模块选项)
|
||||
- [快捷键](#快捷键)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
@ -30,6 +31,9 @@ lang: cn
|
||||
[[layers]]
|
||||
name = "VersionControl"
|
||||
```
|
||||
## 模块选项
|
||||
|
||||
`enable-gtm-status`: 在状态栏展示当前分支工作的时间,这一特性需要安装 [gtm](https://github.com/git-time-metric/gtm) 命令。
|
||||
|
||||
## 快捷键
|
||||
|
||||
|
@ -10,6 +10,7 @@ description: "This layers provides general version control feature for vim. It s
|
||||
- [Description](#description)
|
||||
- [Features](#features)
|
||||
- [Install](#install)
|
||||
- [Layer options](#layer-options)
|
||||
- [Key bindings](#key-bindings)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
@ -33,6 +34,11 @@ To use this configuration layer, update custom configuration file with:
|
||||
name = "VersionControl"
|
||||
```
|
||||
|
||||
## Layer options
|
||||
|
||||
`enable-gtm-status`: Enable diplaying time spent within SpaceVim's statusline. This feature need [gtm](https://github.com/git-time-metric/gtm) command to be installed.
|
||||
|
||||
|
||||
## Key bindings
|
||||
|
||||
| Key Binding | Description |
|
||||
|
Loading…
Reference in New Issue
Block a user