diff --git a/autoload/SpaceVim/layers/tools.vim b/autoload/SpaceVim/layers/tools.vim index 6a7cd0143..05e33c45a 100644 --- a/autoload/SpaceVim/layers/tools.vim +++ b/autoload/SpaceVim/layers/tools.vim @@ -22,7 +22,7 @@ function! SpaceVim#layers#tools#plugins() abort call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-cheat', { 'on_cmd' : 'Cheat'}]) call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-unstack', { 'merged' : 0}]) call add(plugins, ['wsdjeg/Mysql.vim', { 'on_cmd' : 'SQLGetConnection'}]) - call add(plugins, ['wsdjeg/SourceCounter.vim', { 'on_cmd' : 'SourceCounter'}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/SourceCounter.vim', { 'on_cmd' : 'SourceCounter'}]) call add(plugins, [g:_spacevim_root_dir . 'bundle/calendar.vim',{ 'on_cmd' : 'Calendar'}]) call add(plugins, ['junegunn/limelight.vim', { 'on_cmd' : 'Limelight'}]) call add(plugins, ['junegunn/goyo.vim', { 'on_cmd' : 'Goyo', 'loadconf' : 1}]) diff --git a/bundle/SourceCounter.vim/.gitignore b/bundle/SourceCounter.vim/.gitignore new file mode 100644 index 000000000..53336ef4e --- /dev/null +++ b/bundle/SourceCounter.vim/.gitignore @@ -0,0 +1 @@ +doc/tags diff --git a/bundle/SourceCounter.vim/.vintrc.yaml b/bundle/SourceCounter.vim/.vintrc.yaml new file mode 100644 index 000000000..45a77de54 --- /dev/null +++ b/bundle/SourceCounter.vim/.vintrc.yaml @@ -0,0 +1,9 @@ +cmdargs: + # Checking more strictly + severity: style_problem + +policies: + ProhibitImplicitScopeVariable: + enabled: false + ProhibitAbbreviationOption: + enabled: false diff --git a/bundle/SourceCounter.vim/LICENSE b/bundle/SourceCounter.vim/LICENSE new file mode 100644 index 000000000..8084695de --- /dev/null +++ b/bundle/SourceCounter.vim/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Wang Shidong + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bundle/SourceCounter.vim/README.md b/bundle/SourceCounter.vim/README.md new file mode 100644 index 000000000..c1f0897c2 --- /dev/null +++ b/bundle/SourceCounter.vim/README.md @@ -0,0 +1,18 @@ +# SourceCounter.vim + +> source counter in vim + +### Useage + +- `:SourceCounter` : Display result in cmdline +- `:SourceCounter!` : Display result in new tab + +### Options + +- `g:source_counter_sort` : sort method of result, by default, it is `files`, and if you want to sort by lines, use `let g:source_counter_sort = 'lines'` + +### Screenshot + +![SourceCounter](pic/screen.png) + + diff --git a/bundle/SourceCounter.vim/addon-info.json b/bundle/SourceCounter.vim/addon-info.json new file mode 100644 index 000000000..3a657a0c2 --- /dev/null +++ b/bundle/SourceCounter.vim/addon-info.json @@ -0,0 +1,5 @@ +{ + "name": "SourceCounter.vim", + "description": "Source counter in vim", + "author": "wsdjeg" +} diff --git a/bundle/SourceCounter.vim/autoload/SourceCounter.vim b/bundle/SourceCounter.vim/autoload/SourceCounter.vim new file mode 100644 index 000000000..4a3a5aa0b --- /dev/null +++ b/bundle/SourceCounter.vim/autoload/SourceCounter.vim @@ -0,0 +1,138 @@ +scriptencoding utf-8 +let s:support_ft = ['vim', 'java', 'c', 'py', 'md', 'txt'] +function! SourceCounter#View(bang, ...) abort + let result = [] + if a:0 + let fts = a:000 + else + let fts = s:support_ft + endif + echom string(fts) + for ft in fts + let _rs = s:counter(ft) + if !empty(_rs) + call add(result, _rs) + endif + endfor + let result = sort(deepcopy(result), function('s:compare')) + let table = s:draw_table(result) + if a:bang + tabnew + for line in table + call append(line('$'), line) + endfor + else + echo join(table, "\n") + endif +endfunction + +function! s:compare(a, b) abort + let m = get(g:, 'source_counter_sort', 'files') + if m ==# 'lines' + return a:a[2] == a:b[2] ? 0 : a:a[2] > a:b[2] ? -1 : 1 + else + return a:a[1] == a:b[1] ? 0 : a:a[1] > a:b[1] ? -1 : 1 + endif +endfunction +" https://en.wikipedia.org/wiki/Box-drawing_character +function! s:draw_table(rst) abort + if &encoding ==# 'utf-8' + let top_left_corner = '╭' + let top_right_corner = '╮' + let bottom_left_corner = '╰' + let bottom_right_corner = '╯' + let side = '│' + let top_bottom_side = '─' + let middle = '┼' + let top_middle = '┬' + let left_middle = '├' + let right_middle = '┤' + let bottom_middle = '┴' + else + let top_left_corner = '*' + let top_right_corner = '*' + let bottom_left_corner = '*' + let bottom_right_corner = '*' + let side = '|' + let top_bottom_side = '-' + let middle = '*' + let top_middle = '*' + let left_middle = '*' + let right_middle = '*' + let bottom_middle = '*' + endif + let table = [] + let top_line = top_left_corner + \ . repeat(top_bottom_side, 15) + \ . top_middle + \ . repeat(top_bottom_side, 15) + \ . top_middle + \ . repeat(top_bottom_side, 15) + \ . top_right_corner + + let middle_line = left_middle + \ . repeat(top_bottom_side, 15) + \ . middle + \ . repeat(top_bottom_side, 15) + \ . middle + \ . repeat(top_bottom_side, 15) + \ . right_middle + + let bottom_line = bottom_left_corner + \ . repeat(top_bottom_side, 15) + \ . bottom_middle + \ . repeat(top_bottom_side, 15) + \ . bottom_middle + \ . repeat(top_bottom_side, 15) + \ . bottom_right_corner + + call add(table, top_line) + let result = [['filetype', 'files', 'lines']] + a:rst + for rsl in result + let ft_line = side + \ . rsl[0] . repeat(' ', 15 - strwidth(rsl[0])) + \ . side + \ . rsl[1] . repeat(' ', 15 - strwidth(rsl[1])) + \ . side + \ . rsl[2] . repeat(' ', 15 - strwidth(rsl[2])) + \ . side + call add(table, ft_line) + call add(table, middle_line) + endfor + let table[-1] = bottom_line + return table +endfunction + +function! s:counter(ft) abort + let path = getcwd() + let partten = '**/*.' . a:ft + if executable('ag') + if has('nvim') + let files = systemlist(['ag','-g', '.' . a:ft . '$']) + else + let files = split(system('ag -g .'.a:ft.'$'),nr2char(10)) + endif + else + let files = globpath(l:path, l:partten, 0, 1) + endif + if len(files) == 0 + return [] + endif + let lines = 0 + if has('nvim') + if len(files) > 380 + while !empty(files) + let lines += matchstr(systemlist(['wc', '-l'] + remove(files, 0, min([380, len(files) - 1])))[-1], '\d\+') + endwhile + else + let lines = matchstr(systemlist(['wc', '-l'] + files)[-1], '\d\+') + endif + else + for fl in files + let lines += str2nr(matchstr(system('wc -l '. fl), '\d\+')) + endfor + endif + return [a:ft, len(files), lines] +endfunction + + diff --git a/bundle/SourceCounter.vim/doc/SourceCounter.vim.txt b/bundle/SourceCounter.vim/doc/SourceCounter.vim.txt new file mode 100644 index 000000000..85d440321 --- /dev/null +++ b/bundle/SourceCounter.vim/doc/SourceCounter.vim.txt @@ -0,0 +1,35 @@ +*SourceCounter.vim.txt* Source counter in vim +wsdjeg *SourceCounter.vim* + +============================================================================== +CONTENTS *SourceCounter.vim-contents* + 1. Introduction....................................|SourceCounter.vim-intro| + 2. Configuration..................................|SourceCounter.vim-config| + 3. Commands.....................................|SourceCounter.vim-commands| + +============================================================================== +INTRODUCTION *SourceCounter.vim-intro* + +Sources counter for vim and neovim. + +USAGE: +> + :SourceCounter! vim md java html +< + +============================================================================== +CONFIGURATION *SourceCounter.vim-config* + + *g:source_counter_sort* +specific the sort type of result, 'lines' or 'files', default is 'files'. + +============================================================================== +COMMANDS *SourceCounter.vim-commands* + +:SourceCounter[!] [filetypes] *:SourceCounter* + List lines count for specific [filetypes], or all supported filetypes. + + [!] forces desplay result in new tab. + + +vim:tw=78:ts=8:ft=help:norl: diff --git a/bundle/SourceCounter.vim/pic/screen.png b/bundle/SourceCounter.vim/pic/screen.png new file mode 100644 index 000000000..70445d790 Binary files /dev/null and b/bundle/SourceCounter.vim/pic/screen.png differ diff --git a/bundle/SourceCounter.vim/plugin/SourceCounter.vim b/bundle/SourceCounter.vim/plugin/SourceCounter.vim new file mode 100644 index 000000000..b0d4ee8d4 --- /dev/null +++ b/bundle/SourceCounter.vim/plugin/SourceCounter.vim @@ -0,0 +1,28 @@ + +"" +" @section Introduction, intro +" Sources counter for vim and neovim. +" +" USAGE: +" > +" :SourceCounter! vim md java html +" < + +let s:save_cpo = &cpoptions +set cpoptions&vim + +"" +" List lines count for specific [filetypes], or all supported filetypes. +" +" [!] forces desplay result in new tab. +command! -bang -nargs=* SourceCounter call SourceCounter#View('!' ==# '', ) + +if !exists('g:source_counter_sort') + "" + " specific the sort type of result, 'lines' or 'files', default is + " 'files'. + let g:source_counter_sort = 'files' +endif + +let &cpoptions = s:save_cpo +unlet s:save_cpo