From d39fa4697a6251eb339b71e7894cfe334bc92b22 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sat, 10 Sep 2016 20:35:42 +0200 Subject: [PATCH] Updated --- cava/.config/cava/config | 105 +++ gtk/.config/gtk-3.0/gtk.css | 18 +- nvim/.config/nvim/.netrwhist | 4 +- nvim/.config/nvim/autoload/plug.vim | 671 ++++++++++++------ nvim/.config/nvim/autoload/plug.vim.old | 617 ++++++++++------ nvim/.config/nvim/init.vim | 79 ++- nvim/.config/nvim/plugged/LanguageTool | 1 + nvim/.config/nvim/plugged/YouCompleteMe | 2 +- nvim/.config/nvim/plugged/ctrlp-py-matcher | 2 +- nvim/.config/nvim/plugged/ctrlp.vim | 2 +- nvim/.config/nvim/plugged/deoplete.nvim | 1 + nvim/.config/nvim/plugged/glsl.vim | 2 +- nvim/.config/nvim/plugged/gruvbox | 2 +- nvim/.config/nvim/plugged/indentLine | 2 +- nvim/.config/nvim/plugged/nerdtree | 2 +- nvim/.config/nvim/plugged/tcomment_vim | 2 +- nvim/.config/nvim/plugged/tlib_vim | 2 +- nvim/.config/nvim/plugged/todo.txt-vim | 2 +- nvim/.config/nvim/plugged/ultisnips | 2 +- nvim/.config/nvim/plugged/vim-airline | 2 +- nvim/.config/nvim/plugged/vim-bbye | 1 + nvim/.config/nvim/plugged/vim-dispatch | 2 +- nvim/.config/nvim/plugged/vim-fugitive | 1 + nvim/.config/nvim/plugged/vim-glsl | 1 + nvim/.config/nvim/plugged/vim-javascript | 1 + .../nvim/plugged/vim-javascript-syntax | 1 + nvim/.config/nvim/plugged/vim-snippets | 2 +- nvim/.config/nvim/plugged/vim-tmux-navigator | 2 +- nvim/.config/nvim/plugged/vim-unimpaired | 2 +- nvim/.config/nvim/plugged/vim-z80 | 1 + scripts/config_gen.py | 456 ++++++++++++ scripts/fake-toolchain/Unix/ar | 1 + scripts/fake-toolchain/Unix/as | 1 + scripts/fake-toolchain/Unix/cc | 14 + scripts/fake-toolchain/Unix/clang | 1 + scripts/fake-toolchain/Unix/clang++ | 1 + scripts/fake-toolchain/Unix/cxx | 14 + scripts/fake-toolchain/Unix/g++ | 1 + scripts/fake-toolchain/Unix/gcc | 1 + scripts/fake-toolchain/Unix/gcc++ | 1 + scripts/fake-toolchain/Unix/ld | 1 + scripts/fake-toolchain/Unix/nm | 1 + scripts/fake-toolchain/Unix/true | 4 + scripts/spacey | 1 - scripts/template.py | 134 ++++ scripts/watchfile | 206 ++++++ tmux/.tmux.conf | 1 - zsh/.zshrc | 6 +- 48 files changed, 1876 insertions(+), 503 deletions(-) create mode 100644 cava/.config/cava/config create mode 160000 nvim/.config/nvim/plugged/LanguageTool create mode 160000 nvim/.config/nvim/plugged/deoplete.nvim create mode 160000 nvim/.config/nvim/plugged/vim-bbye create mode 160000 nvim/.config/nvim/plugged/vim-fugitive create mode 160000 nvim/.config/nvim/plugged/vim-glsl create mode 160000 nvim/.config/nvim/plugged/vim-javascript create mode 160000 nvim/.config/nvim/plugged/vim-javascript-syntax create mode 160000 nvim/.config/nvim/plugged/vim-z80 create mode 100755 scripts/config_gen.py create mode 120000 scripts/fake-toolchain/Unix/ar create mode 120000 scripts/fake-toolchain/Unix/as create mode 100755 scripts/fake-toolchain/Unix/cc create mode 120000 scripts/fake-toolchain/Unix/clang create mode 120000 scripts/fake-toolchain/Unix/clang++ create mode 100755 scripts/fake-toolchain/Unix/cxx create mode 120000 scripts/fake-toolchain/Unix/g++ create mode 120000 scripts/fake-toolchain/Unix/gcc create mode 120000 scripts/fake-toolchain/Unix/gcc++ create mode 120000 scripts/fake-toolchain/Unix/ld create mode 120000 scripts/fake-toolchain/Unix/nm create mode 100755 scripts/fake-toolchain/Unix/true create mode 100644 scripts/template.py create mode 100755 scripts/watchfile diff --git a/cava/.config/cava/config b/cava/.config/cava/config new file mode 100644 index 0000000..9f30648 --- /dev/null +++ b/cava/.config/cava/config @@ -0,0 +1,105 @@ +## Configuration file for CAVA. Default values are commented out. Use either ; or # for commenting. + + +[general] + +# smoothing mode, can be normal, scientific or waves. +; mode = waves + +# Framerate Default: 60. Accepts only non-negative values. +; framerate = 60 + +# Sensitivity in %. If you think the bars are to low/response is to littei, try +# increasing this value 200 means double height. Accepts only non-negative values. +sensitivity = 1.5 + +# Autosens will atempt to decrease sensitivity if cava peaks. 1 = on, 0 = off +autosens = 0 + +# The number of bars. 0 (default) sets it to auto (fil upp console). +# width of bras and space between bars in number of characters. Default witdth 3 and space 1. +; bars = 0 +bar_width = 2 +bar_spacing = 1 + + +# Lower cutoff freq for lowest bar and higheset for highest bar +# the bandwith of the visualizer, defaults to 50 - 10000 Hz +# Note: there is a minimum total bandwith of 43Mhz x number of bars. +# Cava will automaticly increase the higher cuttoff if a too low band is specified. +lower_cutoff_freq = 50 +higher_cutoff_freq = 10000 + + + +[input] + +# method of capturing audio, supported input methods are: 'pulse', 'alsa' or 'fifo'. +# Defaults to 'alsa' +# +# for pulseaudio 'source' wil be the source. Default: 'NULL', which uses system default source +# all pulseaudio sinks(outputs) have 'monitor' sources(inputs) associated with them +# but the default, might be your microphone, try the command 'pacmd list-sources' to find the right one +# you can change source here to the name of your prefered device, or cahnge your default pulseaudio source by running +# 'pacmd set-default-source NAME|#N' +# +# for alsa 'source' will be the capture device. Default: 'hw:Loopback,1' +# for fifo 'source' will be the path to fifo-file. Default: '/tmp/mpd.fifo' +; method = alsa +; source = hw:Loopback,1 + +; method = fifo +; source = /tmp/mpd.fifo + +; method = pulse +; source = NULL + + + + +[output] + +# method used to draw output may be ncurses, noncurses. +; method = ncurses + +# visual styles, may be 'stereo' or 'mono'. +# Stereo mirrors both channels with low frequencies in center. +# Mono avrages both channels and outputs left to right lowest to highest frequencies +style = mono + + +[color] + +# supported colors are: red, green, yellow, magenta, cyan, white, blue, black. +; background = black +foreground = red + + +[smoothing] + +# multiplier for the integral smoothing calculations. Takes values from 0 - 0.99. +# Higher values means smoother, but less precise. 0 to disable. +; integral = 0.7 + +# disables or enables the so-called "Monstercat smoothing". Default: 1. Set to 0 to disable. +; monstercat = 1 + +# Set gravity multiplier for "drop off". Higher values means bars will drop faster. +# Accepts only non-negative values. 0.5 means half gravity, 2 means double. Set to 0 to disable "drop off". +gravity = 3 + + +# In bar height, bars that whould have been lower that this will not be drawn. +; ignore = 0 + + +[eq] + +# This one is tricky. You can have as much keys as you want. +# remember to uncomment more then one key! More keys = more precision. +# Look at readme.md on github for further explanations and examples. +; 1 = 1 # bass +; 2 = 1 +; 3 = 1 # midtone +; 4 = 1 +; 5 = 1 # treble diff --git a/gtk/.config/gtk-3.0/gtk.css b/gtk/.config/gtk-3.0/gtk.css index 2b39808..cb13745 100644 --- a/gtk/.config/gtk-3.0/gtk.css +++ b/gtk/.config/gtk-3.0/gtk.css @@ -1,12 +1,12 @@ -.header-bar.default-decoration { - padding-top: 3px; - padding-bottom: 3px; -} - -.header-bar.default-decoration .button.titlebutton { - padding-top: 2px; - padding-bottom: 2px; -} +/* .header-bar.default-decoration { */ +/* padding-top: 3px; */ +/* padding-bottom: 3px; */ +/* } */ +/* */ +/* .header-bar.default-decoration .button.titlebutton { */ +/* padding-top: 2px; */ +/* padding-bottom: 2px; */ +/* } */ /* .window-frame:backdrop, */ /* .window-frame, */ diff --git a/nvim/.config/nvim/.netrwhist b/nvim/.config/nvim/.netrwhist index 9063128..d69591a 100644 --- a/nvim/.config/nvim/.netrwhist +++ b/nvim/.config/nvim/.netrwhist @@ -1,4 +1,6 @@ let g:netrw_dirhistmax =10 -let g:netrw_dirhist_cnt =2 +let g:netrw_dirhist_cnt =4 let g:netrw_dirhist_1='/home/tim/.nvim' let g:netrw_dirhist_2='/home/tim/.dotfiles/nvim/.nvim' +let g:netrw_dirhist_3='/home/tim/Projects/cpp/arena' +let g:netrw_dirhist_4='/home/tim/Projects/cpp/stdany' diff --git a/nvim/.config/nvim/autoload/plug.vim b/nvim/.config/nvim/autoload/plug.vim index b63d777..b3bc1a6 100644 --- a/nvim/.config/nvim/autoload/plug.vim +++ b/nvim/.config/nvim/autoload/plug.vim @@ -11,9 +11,13 @@ " call plug#begin('~/.vim/plugged') " " " Make sure you use single quotes -" Plug 'junegunn/seoul256.vim' +" +" " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align " Plug 'junegunn/vim-easy-align' " +" " Any valid git URL is allowed +" Plug 'https://github.com/junegunn/vim-github-dashboard.git' +" " " Group dependencies, vim-snippets depends on ultisnips " Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' " @@ -21,14 +25,17 @@ " Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " Plug 'tpope/vim-fireplace', { 'for': 'clojure' } " -" " Using git URL -" Plug 'https://github.com/junegunn/vim-github-dashboard.git' +" " Using a non-master branch +" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } +" +" " Using a tagged release; wildcard allowed (requires git 1.9.2 or above) +" Plug 'fatih/vim-go', { 'tag': '*' } " " " Plugin options " Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' } " " " Plugin outside ~/.vim/plugged with post-update hook -" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' } +" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " " " Unmanaged plugin (manually installed and updated) " Plug '~/my-prototype-plugin' @@ -37,10 +44,24 @@ " call plug#end() " " Then reload .vimrc and :PlugInstall to install plugins. -" Visit https://github.com/junegunn/vim-plug for more information. +" +" Plug options: +" +"| Option | Description | +"| ----------------------- | ------------------------------------------------ | +"| `branch`/`tag`/`commit` | Branch/tag/commit of the repository to use | +"| `rtp` | Subdirectory that contains Vim plugin | +"| `dir` | Custom directory for the plugin | +"| `as` | Use different name for the plugin | +"| `do` | Post-update hook (string or funcref) | +"| `on` | On-demand loading: Commands or ``-mappings | +"| `for` | On-demand loading: File types | +"| `frozen` | Do not update unless explicitly specified | +" +" More information: https://github.com/junegunn/vim-plug " " -" Copyright (c) 2015 Junegunn Choi +" Copyright (c) 2016 Junegunn Choi " " MIT License " @@ -110,17 +131,17 @@ function! plug#begin(...) endfunction function! s:define_commands() - command! -nargs=+ -bar Plug call s:add() + command! -nargs=+ -bar Plug call plug#() if !executable('git') - return s:err('`git` executable not found. vim-plug requires git.') + return s:err('`git` executable not found. Most commands will not be available. To suppress this message, prepend `silent!` to `call plug#begin(...)`.') endif - command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('' == '!', []) - command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('' == '!', []) - command! -nargs=0 -bar -bang PlugClean call s:clean('' == '!') + command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(0, []) + command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(0, []) + command! -nargs=0 -bar -bang PlugClean call s:clean(0) command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(s:me) | endif command! -nargs=0 -bar PlugStatus call s:status() command! -nargs=0 -bar PlugDiff call s:diff() - command! -nargs=? -bar PlugSnapshot call s:snapshot() + command! -nargs=? -bar -bang -complete=file PlugSnapshot call s:snapshot(0, ) endfunction function! s:to_a(v) @@ -131,18 +152,35 @@ function! s:to_s(v) return type(a:v) == s:TYPE.string ? a:v : join(a:v, "\n") . "\n" endfunction +function! s:glob(from, pattern) + return s:lines(globpath(a:from, a:pattern)) +endfunction + function! s:source(from, ...) + let found = 0 for pattern in a:000 - for vim in s:lines(globpath(a:from, pattern)) + for vim in s:glob(a:from, pattern) execute 'source' s:esc(vim) + let found = 1 endfor endfor + return found endfunction function! s:assoc(dict, key, val) let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) endfunction +function! s:ask(message) + call inputsave() + echohl WarningMsg + let proceed = input(a:message.' (y/N) ') =~? '^y' + echohl None + call inputrestore() + echo "\r" + return proceed +endfunction + function! plug#end() if !exists('g:plugs') return s:err('Call plug#begin() first') @@ -172,11 +210,14 @@ function! plug#end() call s:assoc(lod.map, cmd, name) endif call add(s:triggers[name].map, cmd) - elseif cmd =~ '^[A-Z]' + elseif cmd =~# '^[A-Z]' if exists(':'.cmd) != 2 call s:assoc(lod.cmd, cmd, name) endif call add(s:triggers[name].cmd, cmd) + else + call s:err('Invalid `on` option: '.cmd. + \ '. Should start with an uppercase letter or ``.') endif endfor endif @@ -184,7 +225,9 @@ function! plug#end() if has_key(plug, 'for') let types = s:to_a(plug.for) if !empty(types) + augroup filetypedetect call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') + augroup END endif for type in types call s:assoc(lod.ft, type, name) @@ -217,7 +260,9 @@ function! plug#end() call s:reorg_rtp() filetype plugin indent on if has('vim_starting') - syntax enable + if has('syntax') && !exists('g:syntax_on') + syntax enable + end else call s:reload() endif @@ -248,8 +293,9 @@ function! s:version_requirement(val, min) endfunction function! s:git_version_requirement(...) - let s:git_version = get(s:, 'git_version', - \ map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)')) + if !exists('s:git_version') + let s:git_version = map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)') + endif return s:version_requirement(s:git_version, a:000) endfunction @@ -294,9 +340,14 @@ endif function! s:err(msg) echohl ErrorMsg - echom a:msg + echom '[vim-plug] '.a:msg + echohl None +endfunction + +function! s:warn(cmd, msg) + echohl WarningMsg + execute a:cmd 'a:msg' echohl None - return 0 endfunction function! s:esc(path) @@ -345,6 +396,10 @@ function! s:reorg_rtp() endif endfunction +function! s:doautocmd(...) + execute 'doautocmd' ((v:version > 703 || has('patch442')) ? '' : '') join(a:000) +endfunction + function! plug#load(...) if a:0 == 0 return s:err('Argument missing: plugin name(s) required') @@ -380,7 +435,7 @@ function! s:remove_triggers(name) call remove(s:triggers, a:name) endfunction -function! s:lod(names, types) +function! s:lod(names, types, ...) for name in a:names call s:remove_triggers(name) let s:loaded[name] = 1 @@ -392,14 +447,21 @@ function! s:lod(names, types) for dir in a:types call s:source(rtp, dir.'/**/*.vim') endfor + if a:0 + if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2)) + execute 'runtime' a:1 + endif + call s:source(rtp, a:2) + endif if exists('#User#'.name) - execute 'doautocmd User' name + call s:doautocmd('User', name) endif endfor endfunction function! s:lod_ft(pat, names) - call s:lod(a:names, ['plugin', 'after/plugin', 'syntax', 'after/syntax']) + let syn = 'syntax/'.a:pat.'.vim' + call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn) execute 'autocmd! PlugLOD FileType' a:pat if exists('#filetypeplugin#FileType') doautocmd filetypeplugin FileType @@ -427,16 +489,16 @@ function! s:lod_map(map, names, prefix) call feedkeys(a:prefix . substitute(a:map, '^', "\", '') . extra) endfunction -function! s:add(repo, ...) +function! plug#(repo, ...) if a:0 > 1 return s:err('Invalid number of arguments (1..2)') endif try let repo = s:trim(a:repo) - let name = fnamemodify(repo, ':t:s?\.git$??') - let spec = extend(s:infer_properties(name, repo), - \ a:0 == 1 ? s:parse_options(a:1) : s:base_spec) + let opts = a:0 == 1 ? s:parse_options(a:1) : s:base_spec + let name = get(opts, 'as', fnamemodify(repo, ':t:s?\.git$??')) + let spec = extend(s:infer_properties(name, repo), opts) if !has_key(g:plugs, name) call add(g:plugs_order, name) endif @@ -515,16 +577,22 @@ function! s:syntax() syn match plugStar /^*/ syn match plugMessage /\(^- \)\@<=.*/ syn match plugName /\(^- \)\@<=[^ ]*:/ + syn match plugSha /\%(: \)\@<=[0-9a-f]\{4,}$/ + syn match plugTag /(tag: [^)]\+)/ syn match plugInstall /\(^+ \)\@<=[^:]*/ syn match plugUpdate /\(^* \)\@<=[^:]*/ - syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha - syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained + syn match plugCommit /^ \X*[0-9a-f]\{7} .*/ contains=plugRelDate,plugEdge,plugTag + syn match plugEdge /^ \X\+$/ + syn match plugEdge /^ \X*/ contained nextgroup=plugSha + syn match plugSha /[0-9a-f]\{7}/ contained syn match plugRelDate /([^)]*)$/ contained syn match plugNotLoaded /(not loaded)$/ syn match plugError /^x.*/ + syn match plugH2 /^.*:\n-\+$/ syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean hi def link plug1 Title hi def link plug2 Repeat + hi def link plugH2 Type hi def link plugX Exception hi def link plugBracket Structure hi def link plugNumber Number @@ -540,7 +608,9 @@ function! s:syntax() hi def link plugError Error hi def link plugRelDate Comment + hi def link plugEdge PreProc hi def link plugSha Identifier + hi def link plugTag Constant hi def link plugNotLoaded Comment endfunction @@ -599,32 +669,45 @@ function! s:switch_out(...) endif endfunction -function! s:prepare() +function! s:finish_bindings() + nnoremap R :call retry() + nnoremap D :PlugDiff + nnoremap S :PlugStatus + nnoremap U :call status_update() + xnoremap U :call status_update() + nnoremap ]] :silent! call section('') + nnoremap [[ :silent! call section('b') +endfunction + +function! s:prepare(...) + if empty(getcwd()) + throw 'Invalid current working directory. Cannot proceed.' + endif + call s:job_abort() if s:switch_in() - silent %d _ - else - call s:new_window() - nnoremap q :if b:plug_preview==1pcendifechoq - nnoremap R :silent! call retry() - nnoremap D :PlugDiff - nnoremap S :PlugStatus - nnoremap U :call status_update() - xnoremap U :call status_update() - nnoremap ]] :silent! call section('') - nnoremap [[ :silent! call section('b') - let b:plug_preview = -1 - let s:plug_tab = tabpagenr() - let s:plug_buf = winbufnr(0) - call s:assign_name() + normal q endif + + call s:new_window() + nnoremap q :if b:plug_preview==1pcendifbd + if a:0 == 0 + call s:finish_bindings() + endif + let b:plug_preview = -1 + let s:plug_tab = tabpagenr() + let s:plug_buf = winbufnr(0) + call s:assign_name() + silent! unmap silent! unmap L silent! unmap o silent! unmap X setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable setf vim-plug - call s:syntax() + if exists('g:syntax_on') + call s:syntax() + endif endfunction function! s:assign_name() @@ -639,6 +722,38 @@ function! s:assign_name() silent! execute 'f' fnameescape(name) endfunction +function! s:chsh(swap) + let prev = [&shell, &shellredir] + if !s:is_win && a:swap + set shell=sh shellredir=>%s\ 2>&1 + endif + return prev +endfunction + +function! s:bang(cmd, ...) + try + let [sh, shrd] = s:chsh(a:0) + " FIXME: Escaping is incomplete. We could use shellescape with eval, + " but it won't work on Windows. + let cmd = a:0 ? s:with_cd(a:cmd, a:1) : a:cmd + let g:_plug_bang = '!'.escape(cmd, '#!%') + execute "normal! :execute g:_plug_bang\\" + finally + unlet g:_plug_bang + let [&shell, &shellredir] = [sh, shrd] + endtry + return v:shell_error ? 'Exit status: ' . v:shell_error : '' +endfunction + +function! s:regress_bar() + let bar = substitute(getline(2)[1:-2], '.*\zs=', 'x', '') + call s:progress_bar(2, bar, len(bar)) +endfunction + +function! s:is_updated(dir) + return !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', a:dir)) +endfunction + function! s:do(pull, force, todo) for [name, spec] in items(a:todo) if !isdirectory(spec.dir) @@ -646,45 +761,56 @@ function! s:do(pull, force, todo) endif let installed = has_key(s:update.new, name) let updated = installed ? 0 : - \ (a:pull && index(s:update.errors, name) < 0 && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir))) + \ (a:pull && index(s:update.errors, name) < 0 && s:is_updated(spec.dir)) if a:force || installed || updated execute 'cd' s:esc(spec.dir) call append(3, '- Post-update hook for '. name .' ... ') + let error = '' let type = type(spec.do) if type == s:TYPE.string - try - " FIXME: Escaping is incomplete. We could use shellescape with eval, - " but it won't work on Windows. - let g:_plug_do = '!'.escape(spec.do, '#!%') - execute "normal! :execute g:_plug_do\\" - finally - let result = v:shell_error ? ('Exit status: '.v:shell_error) : 'Done!' - unlet g:_plug_do - endtry + let error = s:bang(spec.do) elseif type == s:TYPE.funcref try let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged') call spec.do({ 'name': name, 'status': status, 'force': a:force }) - let result = 'Done!' catch - let result = 'Error: ' . v:exception + let error = v:exception endtry else - let result = 'Error: Invalid type!' + let error = 'Invalid hook type' + endif + call setline(4, empty(error) ? (getline(4) . 'OK') + \ : ('x' . getline(4)[1:] . error)) + if !empty(error) + call add(s:update.errors, name) + call s:regress_bar() endif - call setline(4, getline(4) . result) cd - endif endfor endfunction +function! s:hash_match(a, b) + return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0 +endfunction + +function! s:checkout(spec) + let sha = a:spec.commit + let output = s:system('git rev-parse HEAD', a:spec.dir) + if !v:shell_error && !s:hash_match(sha, s:lines(output)[0]) + let output = s:system( + \ 'git fetch --depth 999999 && git checkout '.s:esc(sha), a:spec.dir) + endif + return output +endfunction + function! s:finish(pull) let new_frozen = len(filter(keys(s:update.new), 'g:plugs[v:val].frozen')) if new_frozen let s = new_frozen > 1 ? 's' : '' call append(3, printf('- Installed %d frozen plugin%s', new_frozen, s)) endif - call append(3, '- Finishing ... ') + call append(3, '- Finishing ... ') | 4 redraw call plug#helptags() call plug#end() @@ -699,12 +825,14 @@ function! s:finish(pull) call add(msgs, "Press 'D' to see the updated changes.") endif echo join(msgs, ' ') + call s:finish_bindings() endfunction function! s:retry() if empty(s:update.errors) return endif + echo call s:update_impl(s:update.pull, s:update.force, \ extend(copy(s:update.errors), [s:update.threads])) endfunction @@ -717,20 +845,27 @@ function! s:names(...) return sort(filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')) endfunction +function! s:check_ruby() + silent! ruby require 'thread'; VIM::command('let g:plug_ruby = 1') + if get(g:, 'plug_ruby', 0) + unlet g:plug_ruby + return 1 + endif + redraw! + return s:warn('echom', 'Warning: Ruby interface is broken') +endfunction + function! s:update_impl(pull, force, args) abort let args = copy(a:args) let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ? - \ remove(args, -1) : get(g:, 'plug_threads', s:is_win ? 1 : 16) + \ remove(args, -1) : get(g:, 'plug_threads', 16) let managed = filter(copy(g:plugs), 's:is_managed(v:key)') let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') : \ filter(managed, 'index(args, v:key) >= 0') if empty(todo) - echohl WarningMsg - echo 'No plugin to '. (a:pull ? 'update' : 'install') . '.' - echohl None - return + return s:warn('echo', 'No plugin to '. (a:pull ? 'update' : 'install')) endif if !s:is_win && s:git_version_requirement(2, 3) @@ -752,14 +887,11 @@ function! s:update_impl(pull, force, args) abort endif if has('nvim') && !exists('*jobwait') && threads > 1 - echohl WarningMsg - echomsg 'vim-plug: update Neovim for parallel installer' - echohl None + call s:warn('echom', '[vim-plug] Update Neovim for parallel installer') endif - let python = (has('python') || has('python3')) && !s:is_win && !has('win32unix') - \ && (!s:nvim || has('vim_starting')) - let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) + let python = (has('python') || has('python3')) && (!s:nvim || has('vim_starting')) + let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && s:check_ruby() let s:update = { \ 'start': reltime(), @@ -774,7 +906,7 @@ function! s:update_impl(pull, force, args) abort \ 'fin': 0 \ } - call s:prepare() + call s:prepare(1) call append(0, ['', '']) normal! 2G silent! redraw @@ -785,7 +917,7 @@ function! s:update_impl(pull, force, args) abort " Python version requirement (>= 2.7) if python && !has('python3') && !ruby && !s:nvim && s:update.threads > 1 redir => pyv - silent python import platform; print(platform.python_version()) + silent python import platform; print platform.python_version() redir END let python = s:version_requirement( \ map(split(split(pyv)[0], '\.'), 'str2nr(v:val)'), [2, 6]) @@ -827,12 +959,61 @@ function! s:update_impl(pull, force, args) abort endif endfunction +function! s:log4(name, msg) + call setline(4, printf('- %s (%s)', a:msg, a:name)) + redraw +endfunction + function! s:update_finish() if exists('s:git_terminal_prompt') let $GIT_TERMINAL_PROMPT = s:git_terminal_prompt endif if s:switch_in() - call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'has_key(v:val, "do")')) + call append(3, '- Updating ...') | 4 + for [name, spec] in items(filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && (s:update.force || s:update.pull || has_key(s:update.new, v:key))')) + let pos = s:logpos(name) + if !pos + continue + endif + if has_key(spec, 'commit') + call s:log4(name, 'Checking out '.spec.commit) + let out = s:checkout(spec) + elseif has_key(spec, 'tag') + let tag = spec.tag + if tag =~ '\*' + let tags = s:lines(s:system('git tag --list '.string(tag).' --sort -version:refname 2>&1', spec.dir)) + if !v:shell_error && !empty(tags) + let tag = tags[0] + call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag)) + call append(3, '') + endif + endif + call s:log4(name, 'Checking out '.tag) + let out = s:system('git checkout -q '.s:esc(tag).' 2>&1', spec.dir) + else + let branch = s:esc(get(spec, 'branch', 'master')) + call s:log4(name, 'Merging origin/'.branch) + let out = s:system('git checkout -q '.branch.' 2>&1' + \. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir) + endif + if !v:shell_error && filereadable(spec.dir.'/.gitmodules') && + \ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir)) + call s:log4(name, 'Updating submodules. This may take a while.') + let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir) + endif + let msg = printf('%s %s: %s', v:shell_error ? 'x': '-', name, s:lastline(out)) + if v:shell_error + call add(s:update.errors, name) + call s:regress_bar() + execute pos 'd _' + call append(4, msg) | 4 + elseif !empty(out) + call setline(pos, msg) + endif + redraw + endfor + 4 d _ + call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && has_key(v:val, "do")')) call s:finish(s:update.pull) call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.') call s:switch_out('normal! gg') @@ -861,7 +1042,13 @@ function! s:job_handler(job_id, data, event) abort endif if a:event == 'stdout' - let self.result .= substitute(s:to_s(a:data), '[\r\n]', '', 'g') . "\n" + let complete = empty(a:data[-1]) + let lines = map(filter(a:data, 'len(v:val) > 0'), 'split(v:val, "[\r\n]")[-1]') + call extend(self.lines, lines) + let self.result = join(self.lines, "\n") + if !complete + call remove(self.lines, -1) + endif " To reduce the number of buffer updates let self.tick = get(self, 'tick', -1) + 1 if self.tick % len(s:jobs) == 0 @@ -878,7 +1065,7 @@ function! s:job_handler(job_id, data, event) abort endfunction function! s:spawn(name, cmd, opts) - let job = { 'name': a:name, 'running': 1, 'error': 0, 'result': '', + let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [], 'result': '', \ 'new': get(a:opts, 'new', 0), \ 'on_stdout': function('s:job_handler'), \ 'on_exit' : function('s:job_handler'), @@ -914,7 +1101,7 @@ function! s:reap(name) endif let s:update.bar .= job.error ? 'x' : '=' - call s:log(job.error ? 'x' : '-', a:name, job.result) + call s:log(job.error ? 'x' : '-', a:name, empty(job.result) ? 'OK' : job.result) call s:bar() call remove(s:jobs, a:name) @@ -931,12 +1118,11 @@ function! s:bar() endfunction function! s:logpos(name) - for i in range(1, line('$')) + for i in range(4, line('$')) if getline(i) =~# '^[-+x*] '.a:name.':' return i endif endfor - return 0 endfunction function! s:log(bullet, name, lines) @@ -982,30 +1168,24 @@ while 1 " Without TCO, Vim stack is bound to explode redraw let has_tag = has_key(spec, 'tag') - let checkout = s:shellesc(has_tag ? spec.tag : spec.branch) - let merge = s:shellesc(has_tag ? spec.tag : 'origin/'.spec.branch) - if !new - let [valid, msg] = s:git_valid(spec, 0) - if valid + let [error, _] = s:git_validate(spec, 0) + if empty(error) if pull let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : '' - call s:spawn(name, - \ printf('(git fetch %s %s 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only %s 2>&1 && git submodule update --init --recursive 2>&1)', - \ fetch_opt, prog, checkout, merge), { 'dir': spec.dir }) + call s:spawn(name, printf('git fetch %s %s 2>&1', fetch_opt, prog), { 'dir': spec.dir }) else let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 } endif else - let s:jobs[name] = { 'running': 0, 'result': msg, 'error': 1 } + let s:jobs[name] = { 'running': 0, 'result': error, 'error': 1 } endif else call s:spawn(name, - \ printf('git clone %s %s --recursive %s -b %s %s 2>&1', + \ printf('git clone %s %s %s %s 2>&1', \ has_tag ? '' : s:clone_opt, \ prog, \ s:shellesc(spec.uri), - \ checkout, \ s:shellesc(s:trim(spec.dir))), { 'new': 1 }) endif @@ -1019,9 +1199,8 @@ endwhile endfunction function! s:update_python() -let py_exe = has('python3') ? 'python3' : 'python' +let py_exe = has('python') ? 'python' : 'python3' execute py_exe "<< EOF" -""" Due to use of signals this function is POSIX only. """ import datetime import functools import os @@ -1048,14 +1227,11 @@ G_CLONE_OPT = vim.eval('s:clone_opt') G_PROGRESS = vim.eval('s:progress_opt(1)') G_LOG_PROB = 1.0 / int(vim.eval('s:update.threads')) G_STOP = thr.Event() -G_THREADS = {} +G_IS_WIN = vim.eval('s:is_win') == '1' class PlugError(Exception): def __init__(self, msg): - self._msg = msg - @property - def msg(self): - return self._msg + self.msg = msg class CmdTimedOut(PlugError): pass class CmdFailed(PlugError): @@ -1066,10 +1242,9 @@ class Action(object): INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-'] class Buffer(object): - def __init__(self, lock, num_plugs, is_pull, is_win): + def __init__(self, lock, num_plugs, is_pull): self.bar = '' self.event = 'Updating' if is_pull else 'Installing' - self.is_win = is_win self.lock = lock self.maxy = int(vim.eval('winheight(".")')) self.num_plugs = num_plugs @@ -1097,8 +1272,7 @@ class Buffer(object): with self.lock: vim.command('normal! 2G') - if not self.is_win: - vim.command('redraw') + vim.command('redraw') def write(self, action, name, lines): first, rest = lines[0], lines[1:] @@ -1127,9 +1301,12 @@ class Buffer(object): pass class Command(object): + CD = 'cd /d' if G_IS_WIN else 'cd' + def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None): self.cmd = cmd - self.cmd_dir = cmd_dir + if cmd_dir: + self.cmd = '{0} {1} && {2}'.format(Command.CD, cmd_dir, self.cmd) self.timeout = timeout self.callback = cb if cb else (lambda msg: None) self.clean = clean if clean else (lambda: None) @@ -1179,9 +1356,11 @@ class Command(object): try: tfile = tempfile.NamedTemporaryFile(mode='w+b') - self.proc = subprocess.Popen(self.cmd, cwd=self.cmd_dir, stdout=tfile, - stderr=subprocess.STDOUT, shell=True, - preexec_fn=os.setsid) + preexec_fn = not G_IS_WIN and os.setsid or None + self.proc = subprocess.Popen(self.cmd, stdout=tfile, + stderr=subprocess.STDOUT, + stdin=subprocess.PIPE, shell=True, + preexec_fn=preexec_fn) thrd = thr.Thread(target=(lambda proc: proc.wait()), args=(self.proc,)) thrd.start() @@ -1199,7 +1378,7 @@ class Command(object): if first_line or random.random() < G_LOG_PROB: first_line = False - line = nonblock_read(tfile.name) + line = '' if G_IS_WIN else nonblock_read(tfile.name) if line: self.callback([line]) @@ -1223,7 +1402,10 @@ class Command(object): def terminate(self): """ Terminate process and cleanup. """ if self.alive: - os.killpg(self.proc.pid, signal.SIGTERM) + if G_IS_WIN: + os.kill(self.proc.pid, signal.SIGINT) + else: + os.killpg(self.proc.pid, signal.SIGTERM) self.clean() class Plugin(object): @@ -1232,10 +1414,7 @@ class Plugin(object): self.args = args self.buf_q = buf_q self.lock = lock - tag = args.get('tag', 0) - self.checkout = esc(tag if tag else args['branch']) - self.merge = esc(tag if tag else 'origin/' + args['branch']) - self.tag = tag + self.tag = args.get('tag', 0) def manage(self): try: @@ -1258,6 +1437,8 @@ class Plugin(object): def install(self): target = self.args['dir'] + if target[-1] == '\\': + target = target[0:-1] def clean(target): def _clean(): @@ -1269,15 +1450,15 @@ class Plugin(object): self.write(Action.INSTALL, self.name, ['Installing ...']) callback = functools.partial(self.write, Action.INSTALL, self.name) - cmd = 'git clone {0} {1} --recursive {2} -b {3} {4} 2>&1'.format( + cmd = 'git clone {0} {1} {2} {3} 2>&1'.format( '' if self.tag else G_CLONE_OPT, G_PROGRESS, self.args['uri'], - self.checkout, esc(target)) + esc(target)) com = Command(cmd, None, G_TIMEOUT, callback, clean(target)) result = com.execute(G_RETRIES) self.write(Action.DONE, self.name, result[-1:]) def repo_uri(self): - cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url' + cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url' command = Command(cmd, self.args['dir'], G_TIMEOUT,) result = command.execute(G_RETRIES) return result[-1] @@ -1297,11 +1478,7 @@ class Plugin(object): self.write(Action.UPDATE, self.name, ['Updating ...']) callback = functools.partial(self.write, Action.UPDATE, self.name) fetch_opt = '--depth 99999999' if self.tag and os.path.isfile(os.path.join(self.args['dir'], '.git/shallow')) else '' - cmds = ['git fetch {0} {1}'.format(fetch_opt, G_PROGRESS), - 'git checkout -q {0}'.format(self.checkout), - 'git merge --ff-only {0}'.format(self.merge), - 'git submodule update --init --recursive'] - cmd = ' 2>&1 && '.join(cmds) + cmd = 'git fetch {0} {1} 2>&1'.format(fetch_opt, G_PROGRESS) com = Command(cmd, self.args['dir'], G_TIMEOUT, callback) result = com.execute(G_RETRIES) self.write(Action.DONE, self.name, result[-1:]) @@ -1329,10 +1506,6 @@ class PlugThread(thr.Thread): work_q.task_done() except queue.Empty: pass - finally: - global G_THREADS - with lock: - del G_THREADS[thr.current_thread().name] class RefreshThread(thr.Thread): def __init__(self, lock): @@ -1378,28 +1551,26 @@ def main(): nthreads = int(vim.eval('s:update.threads')) plugs = vim.eval('s:update.todo') mac_gui = vim.eval('s:mac_gui') == '1' - is_win = vim.eval('s:is_win') == '1' lock = thr.Lock() - buf = Buffer(lock, len(plugs), G_PULL, is_win) + buf = Buffer(lock, len(plugs), G_PULL) buf_q, work_q = queue.Queue(), queue.Queue() for work in plugs.items(): work_q.put(work) - global G_THREADS + start_cnt = thr.active_count() for num in range(nthreads): tname = 'PlugT-{0:02}'.format(num) thread = PlugThread(tname, (buf_q, work_q, lock)) thread.start() - G_THREADS[tname] = thread if mac_gui: rthread = RefreshThread(lock) rthread.start() - while not buf_q.empty() or len(G_THREADS) != 0: + while not buf_q.empty() or thr.active_count() != start_cnt: try: action, name, msg = buf_q.get(True, 0.25) - buf.write(action, name, msg) + buf.write(action, name, ['OK'] if not msg else msg) buf_q.task_done() except queue.Empty: pass @@ -1439,16 +1610,20 @@ function! s:update_ruby() def killall pid pids = [pid] - unless `which pgrep 2> /dev/null`.empty? - children = pids - until children.empty? - children = children.map { |pid| - `pgrep -P #{pid}`.lines.map { |l| l.chomp } - }.flatten - pids += children + if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM + pids.each { |pid| Process.kill 'INT', pid.to_i rescue nil } + else + unless `which pgrep 2> /dev/null`.empty? + children = pids + until children.empty? + children = children.map { |pid| + `pgrep -P #{pid}`.lines.map { |l| l.chomp } + }.flatten + pids += children + end end + pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } end - pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } end require 'thread' @@ -1474,7 +1649,7 @@ function! s:update_ruby() $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})" $curbuf[2] = '[' + bar.ljust(tot) + ']' VIM::command('normal! 2G') - VIM::command('redraw') unless iswin + VIM::command('redraw') } where = proc { |name| (1..($curbuf.length)).find { |l| $curbuf[l] =~ /^[-+x*] #{name}:/ } } log = proc { |name, result, type| @@ -1489,7 +1664,7 @@ function! s:update_ruby() end result = if type || type.nil? - ["#{b} #{name}: #{result.lines.to_a.last}"] + ["#{b} #{name}: #{result.lines.to_a.last || 'OK'}"] elsif result =~ /^Interrupted|^Timeout/ ["#{b} #{name}: #{result}"] else @@ -1579,15 +1754,12 @@ function! s:update_ruby() threads << Thread.new { while pair = take1.call name = pair.first - dir, uri, branch, tag = pair.last.values_at *%w[dir uri branch tag] - checkout = esc(tag ? tag : branch) - merge = esc(tag ? tag : "origin/#{branch}") - subm = "git submodule update --init --recursive 2>&1" + dir, uri, tag = pair.last.values_at *%w[dir uri tag] exists = File.directory? dir ok, result = if exists - dir = iswin ? dir : esc(dir) - ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil + chdir = "#{cd} #{iswin ? dir : esc(dir)}" + ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url", nil, nil, nil current_uri = data.lines.to_a.last if !ret if data =~ /^Interrupted|^Timeout/ @@ -1603,7 +1775,7 @@ function! s:update_ruby() if pull log.call name, 'Updating ...', :update fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : '' - bt.call "#{cd} #{dir} && git fetch #{fetch_opt} #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm}", name, :update, nil + bt.call "#{chdir} && git fetch #{fetch_opt} #{progress} 2>&1", name, :update, nil else [true, skip] end @@ -1611,7 +1783,7 @@ function! s:update_ruby() else d = esc dir.sub(%r{[\\/]+$}, '') log.call name, 'Installing ...', :install - bt.call "git clone #{clone_opt unless tag} #{progress} --recursive #{uri} -b #{checkout} #{d} 2>&1", name, :install, proc { + bt.call "git clone #{clone_opt unless tag} #{progress} #{uri} #{d} 2>&1", name, :install, proc { FileUtils.rm_rf dir } end @@ -1633,7 +1805,7 @@ function! s:shellesc(arg) endfunction function! s:glob_dir(path) - return map(filter(s:lines(globpath(a:path, '**')), 'isdirectory(v:val)'), 's:dirpath(v:val)') + return map(filter(s:glob(a:path, '**'), 'isdirectory(v:val)'), 's:dirpath(v:val)') endfunction function! s:progress_bar(line, bar, total) @@ -1661,10 +1833,7 @@ endfunction function! s:system(cmd, ...) try - let [sh, shrd] = [&shell, &shellredir] - if !s:is_win - set shell=sh shellredir=>%s\ 2>&1 - endif + let [sh, shrd] = s:chsh(1) let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd return system(s:is_win ? '('.cmd.')' : cmd) finally @@ -1677,42 +1846,53 @@ function! s:system_chomp(...) return v:shell_error ? '' : substitute(ret, '\n$', '', '') endfunction -function! s:git_valid(spec, check_branch) - let ret = 1 - let msg = 'OK' +function! s:git_validate(spec, check_branch) + let err = '' if isdirectory(a:spec.dir) - let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url', a:spec.dir)) + let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url', a:spec.dir)) let remote = result[-1] if v:shell_error - let msg = join([remote, 'PlugClean required.'], "\n") - let ret = 0 + let err = join([remote, 'PlugClean required.'], "\n") elseif !s:compare_git_uri(remote, a:spec.uri) - let msg = join(['Invalid URI: '.remote, + let err = join(['Invalid URI: '.remote, \ 'Expected: '.a:spec.uri, \ 'PlugClean required.'], "\n") - let ret = 0 + elseif a:check_branch && has_key(a:spec, 'commit') + let result = s:lines(s:system('git rev-parse HEAD 2>&1', a:spec.dir)) + let sha = result[-1] + if v:shell_error + let err = join(add(result, 'PlugClean required.'), "\n") + elseif !s:hash_match(sha, a:spec.commit) + let err = join([printf('Invalid HEAD (expected: %s, actual: %s)', + \ a:spec.commit[:6], sha[:6]), + \ 'PlugUpdate required.'], "\n") + endif elseif a:check_branch let branch = result[0] " Check tag if has_key(a:spec, 'tag') let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir) if a:spec.tag !=# tag - let msg = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', + let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', \ (empty(tag) ? 'N/A' : tag), a:spec.tag) - let ret = 0 endif " Check branch elseif a:spec.branch !=# branch - let msg = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', + let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', \ branch, a:spec.branch) - let ret = 0 + endif + if empty(err) + let commits = len(s:lines(s:system(printf('git rev-list origin/%s..HEAD', a:spec.branch), a:spec.dir))) + if !v:shell_error && commits + let err = join([printf('Diverged from origin/%s by %d commit(s).', a:spec.branch, commits), + \ 'Reinstall after PlugClean.'], "\n") + endif endif endif else - let msg = 'Not found' - let ret = 0 + let err = 'Not found' endif - return [ret, msg] + return [err, err =~# 'PlugClean'] endfunction function! s:rm_rf(dir) @@ -1723,15 +1903,23 @@ endfunction function! s:clean(force) call s:prepare() - call append(0, 'Searching for unused plugins in '.g:plug_home) + call append(0, 'Searching for invalid plugins in '.g:plug_home) call append(1, '') " List of valid directories let dirs = [] + let errs = {} let [cnt, total] = [0, len(g:plugs)] for [name, spec] in items(g:plugs) - if !s:is_managed(name) || s:git_valid(spec, 0)[0] + if !s:is_managed(name) call add(dirs, spec.dir) + else + let [err, clean] = s:git_validate(spec, 1) + if clean + let errs[spec.dir] = s:lines(err)[0] + else + call add(dirs, spec.dir) + endif endif let cnt += 1 call s:progress_bar(2, repeat('=', cnt), total) @@ -1755,28 +1943,28 @@ function! s:clean(force) if !has_key(allowed, f) && isdirectory(f) call add(todo, f) call append(line('$'), '- ' . f) + if has_key(errs, f) + call append(line('$'), ' ' . errs[f]) + endif let found = filter(found, 'stridx(v:val, f) != 0') end endwhile - normal! G + 4 redraw if empty(todo) call append(line('$'), 'Already clean.') else - call inputsave() - let yes = a:force || (input('Proceed? (y/N) ') =~? '^y') - call inputrestore() - if yes + if a:force || s:ask('Proceed?') for dir in todo call s:rm_rf(dir) endfor - call append(line('$'), 'Removed.') + call append(3, ['Removed.', '']) else - call append(line('$'), 'Cancelled.') + call append(3, ['Cancelled.', '']) endif endif - normal! G + 4 endfunction function! s:upgrade() @@ -1823,7 +2011,8 @@ function! s:status() for [name, spec] in items(g:plugs) if has_key(spec, 'uri') if isdirectory(spec.dir) - let [valid, msg] = s:git_valid(spec, 1) + let [err, _] = s:git_validate(spec, 1) + let [valid, msg] = [empty(err), empty(err) ? 'OK' : err] else let [valid, msg] = [0, 'Not found. Try PlugInstall.'] endif @@ -1886,7 +2075,6 @@ function! s:is_preview_window_open() wincmd p return 1 endif - return 0 endfunction function! s:find_name(lnum) @@ -1908,7 +2096,7 @@ function! s:preview_commit() let b:plug_preview = !s:is_preview_window_open() endif - let sha = matchstr(getline('.'), '\(^ \)\@<=[0-9a-z]\{7}') + let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7}') if empty(sha) return endif @@ -1921,7 +2109,7 @@ function! s:preview_commit() execute 'pedit' sha wincmd P setlocal filetype=git buftype=nofile nobuflisted modifiable - execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --pretty=medium' sha + execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha normal! gg"_dd setlocal nomodifiable nnoremap q :q @@ -1932,41 +2120,72 @@ function! s:section(flags) call search('\(^[x-] \)\@<=[^:]\+:', a:flags) endfunction +function! s:format_git_log(line) + let indent = ' ' + let tokens = split(a:line, nr2char(1)) + if len(tokens) != 5 + return indent.substitute(a:line, '\s*$', '', '') + endif + let [graph, sha, refs, subject, date] = tokens + let tag = matchstr(refs, 'tag: [^,)]\+') + let tag = empty(tag) ? ' ' : ' ('.tag.') ' + return printf('%s%s%s%s%s (%s)', indent, graph, sha, tag, subject, date) +endfunction + +function! s:append_ul(lnum, text) + call append(a:lnum, ['', a:text, repeat('-', len(a:text))]) +endfunction + function! s:diff() call s:prepare() - call append(0, 'Collecting updated changes ...') - normal! gg - redraw - - let cnt = 0 - for [k, v] in items(g:plugs) - if !isdirectory(v.dir) || !s:is_managed(k) + call append(0, ['Collecting changes ...', '']) + let cnts = [0, 0] + let bar = '' + let total = filter(copy(g:plugs), 's:is_managed(v:key) && isdirectory(v:val.dir)') + call s:progress_bar(2, bar, len(total)) + for origin in [1, 0] + let plugs = reverse(sort(items(filter(copy(total), (origin ? '' : '!').'(has_key(v:val, "commit") || has_key(v:val, "tag"))')))) + if empty(plugs) continue endif - - let diff = s:system_chomp('git log --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"', v.dir) - if !empty(diff) - call append(1, '') - call append(2, '- '.k.':') - call append(3, map(s:lines(diff), '" ". v:val')) - let cnt += 1 - normal! gg + call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:') + for [k, v] in plugs + let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..' + let diff = s:system_chomp('git log --graph --color=never --pretty=format:"%x01%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir) + if !empty(diff) + let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' + call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) + let cnts[origin] += 1 + endif + let bar .= '=' + call s:progress_bar(2, bar, len(total)) + normal! 2G redraw + endfor + if !cnts[origin] + call append(5, ['', 'N/A']) endif endfor + call setline(1, printf('%d plugin(s) updated.', cnts[0]) + \ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : '')) - call setline(1, cnt == 0 ? 'No updates.' : 'Last update:') - nnoremap :silent! call preview_commit() - nnoremap o :silent! call preview_commit() - nnoremap X :call revert() - normal! gg - setlocal nomodifiable - if cnt > 0 + if cnts[0] || cnts[1] + nnoremap :silent! call preview_commit() + nnoremap o :silent! call preview_commit() + endif + if cnts[0] + nnoremap X :call revert() echo "Press 'X' on each block to revert the update" endif + normal! gg + setlocal nomodifiable endfunction function! s:revert() + if search('^Pending updates', 'bnW') + return + endif + let name = s:find_name(line('.')) if empty(name) || !has_key(g:plugs, name) || \ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y' @@ -1980,42 +2199,35 @@ function! s:revert() echo 'Reverted.' endfunction -function! s:snapshot(...) abort - let home = get(s:, 'plug_home_org', g:plug_home) - let [type, var, header] = s:is_win ? - \ ['dosbatch', '%PLUG_HOME%', - \ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '', - \ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.home]] : - \ ['sh', '$PLUG_HOME', - \ ['#!/bin/sh', '# Generated by vim-plug', '# '.strftime("%c"), '', - \ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]] - +function! s:snapshot(force, ...) abort call s:prepare() - execute 'setf' type - call append(0, header) - call append('$', '') + setf vim + call append(0, ['" Generated by vim-plug', + \ '" '.strftime("%c"), + \ '" :source this file in vim to restore the snapshot', + \ '" or execute: vim -S snapshot.vim', + \ '', '', 'PlugUpdate!']) 1 - redraw - - let dirs = sort(map(values(filter(copy(g:plugs), - \'has_key(v:val, "uri") && isdirectory(v:val.dir)')), 'v:val.dir')) - let anchor = line('$') - 1 - for dir in reverse(dirs) - let sha = s:system_chomp('git rev-parse --short HEAD', dir) + let anchor = line('$') - 3 + let names = sort(keys(filter(copy(g:plugs), + \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)'))) + for name in reverse(names) + let sha = s:system_chomp('git rev-parse --short HEAD', g:plugs[name].dir) if !empty(sha) - call append(anchor, printf('cd %s && git reset --hard %s', - \ substitute(dir, '^\V'.escape(g:plug_home, '\'), var, ''), sha)) + call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha)) redraw endif endfor if a:0 > 0 let fn = expand(a:1) - let fne = s:esc(fn) + if filereadable(fn) && !(a:force || s:ask(a:1.' already exists. Overwrite?')) + return + endif call writefile(getline(1, '$'), fn) - if !s:is_win | call s:system('chmod +x ' . fne) | endif - echo 'Saved to '.a:1 - silent execute 'e' fne + echo 'Saved as '.a:1 + silent execute 'e' s:esc(fn) + setf vim endif endfunction @@ -2034,4 +2246,3 @@ endif let &cpo = s:cpo_save unlet s:cpo_save - diff --git a/nvim/.config/nvim/autoload/plug.vim.old b/nvim/.config/nvim/autoload/plug.vim.old index 6e14d0e..9cb02f7 100644 --- a/nvim/.config/nvim/autoload/plug.vim.old +++ b/nvim/.config/nvim/autoload/plug.vim.old @@ -11,9 +11,13 @@ " call plug#begin('~/.vim/plugged') " " " Make sure you use single quotes -" Plug 'junegunn/seoul256.vim' +" +" " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align " Plug 'junegunn/vim-easy-align' " +" " Any valid git URL is allowed +" Plug 'https://github.com/junegunn/vim-github-dashboard.git' +" " " Group dependencies, vim-snippets depends on ultisnips " Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' " @@ -21,14 +25,14 @@ " Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " Plug 'tpope/vim-fireplace', { 'for': 'clojure' } " -" " Using git URL -" Plug 'https://github.com/junegunn/vim-github-dashboard.git' +" " Using a non-master branch +" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } " " " Plugin options " Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' } " " " Plugin outside ~/.vim/plugged with post-update hook -" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' } +" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " " " Unmanaged plugin (manually installed and updated) " Plug '~/my-prototype-plugin' @@ -37,7 +41,21 @@ " call plug#end() " " Then reload .vimrc and :PlugInstall to install plugins. -" Visit https://github.com/junegunn/vim-plug for more information. +" +" Plug options: +" +"| Option | Description | +"| ----------------------- | ------------------------------------------------ | +"| `branch`/`tag`/`commit` | Branch/tag/commit of the repository to use | +"| `rtp` | Subdirectory that contains Vim plugin | +"| `dir` | Custom directory for the plugin | +"| `as` | Use different name for the plugin | +"| `do` | Post-update hook (string or funcref) | +"| `on` | On-demand loading: Commands or ``-mappings | +"| `for` | On-demand loading: File types | +"| `frozen` | Do not update unless explicitly specified | +" +" More information: https://github.com/junegunn/vim-plug " " " Copyright (c) 2015 Junegunn Choi @@ -110,17 +128,17 @@ function! plug#begin(...) endfunction function! s:define_commands() - command! -nargs=+ -bar Plug call s:add() + command! -nargs=+ -bar Plug call s:Plug() if !executable('git') - return s:err('`git` executable not found. vim-plug requires git.') + return s:err('`git` executable not found. Most commands will not be available. To suppress this message, prepend `silent!` to `call plug#begin(...)`.') endif - command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('' == '!', []) - command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('' == '!', []) - command! -nargs=0 -bar -bang PlugClean call s:clean('' == '!') + command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(0, []) + command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(0, []) + command! -nargs=0 -bar -bang PlugClean call s:clean(0) command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(s:me) | endif command! -nargs=0 -bar PlugStatus call s:status() command! -nargs=0 -bar PlugDiff call s:diff() - command! -nargs=? -bar PlugSnapshot call s:snapshot() + command! -nargs=? -bar -bang -complete=file PlugSnapshot call s:snapshot(0, ) endfunction function! s:to_a(v) @@ -131,18 +149,35 @@ function! s:to_s(v) return type(a:v) == s:TYPE.string ? a:v : join(a:v, "\n") . "\n" endfunction +function! s:glob(from, pattern) + return s:lines(globpath(a:from, a:pattern)) +endfunction + function! s:source(from, ...) + let found = 0 for pattern in a:000 - for vim in s:lines(globpath(a:from, pattern)) + for vim in s:glob(a:from, pattern) execute 'source' s:esc(vim) + let found = 1 endfor endfor + return found endfunction function! s:assoc(dict, key, val) let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) endfunction +function! s:ask(message) + call inputsave() + echohl WarningMsg + let proceed = input(a:message.' (y/N) ') =~? '^y' + echohl None + call inputrestore() + echo "\r" + return proceed +endfunction + function! plug#end() if !exists('g:plugs') return s:err('Call plug#begin() first') @@ -172,11 +207,14 @@ function! plug#end() call s:assoc(lod.map, cmd, name) endif call add(s:triggers[name].map, cmd) - elseif cmd =~ '^[A-Z]' + elseif cmd =~# '^[A-Z]' if exists(':'.cmd) != 2 call s:assoc(lod.cmd, cmd, name) endif call add(s:triggers[name].cmd, cmd) + else + call s:err('Invalid `on` option: '.cmd. + \ '. Should start with an uppercase letter or ``.') endif endfor endif @@ -217,7 +255,9 @@ function! plug#end() call s:reorg_rtp() filetype plugin indent on if has('vim_starting') - syntax enable + if has('syntax') && !exists('g:syntax_on') + syntax enable + end else call s:reload() endif @@ -248,8 +288,9 @@ function! s:version_requirement(val, min) endfunction function! s:git_version_requirement(...) - let s:git_version = get(s:, 'git_version', - \ map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)')) + if !exists('s:git_version') + let s:git_version = map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)') + endif return s:version_requirement(s:git_version, a:000) endfunction @@ -294,7 +335,7 @@ endif function! s:err(msg) echohl ErrorMsg - echom a:msg + echom '[vim-plug] '.a:msg echohl None return 0 endfunction @@ -380,7 +421,7 @@ function! s:remove_triggers(name) call remove(s:triggers, a:name) endfunction -function! s:lod(names, types) +function! s:lod(names, types, ...) for name in a:names call s:remove_triggers(name) let s:loaded[name] = 1 @@ -392,6 +433,12 @@ function! s:lod(names, types) for dir in a:types call s:source(rtp, dir.'/**/*.vim') endfor + if a:0 + if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2)) + execute 'runtime' a:1 + endif + call s:source(rtp, a:2) + endif if exists('#User#'.name) execute 'doautocmd User' name endif @@ -399,7 +446,8 @@ function! s:lod(names, types) endfunction function! s:lod_ft(pat, names) - call s:lod(a:names, ['plugin', 'after/plugin']) + let syn = 'syntax/'.a:pat.'.vim' + call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn) execute 'autocmd! PlugLOD FileType' a:pat if exists('#filetypeplugin#FileType') doautocmd filetypeplugin FileType @@ -427,16 +475,16 @@ function! s:lod_map(map, names, prefix) call feedkeys(a:prefix . substitute(a:map, '^', "\", '') . extra) endfunction -function! s:add(repo, ...) +function! s:Plug(repo, ...) if a:0 > 1 return s:err('Invalid number of arguments (1..2)') endif try let repo = s:trim(a:repo) - let name = fnamemodify(repo, ':t:s?\.git$??') - let spec = extend(s:infer_properties(name, repo), - \ a:0 == 1 ? s:parse_options(a:1) : s:base_spec) + let opts = a:0 == 1 ? s:parse_options(a:1) : s:base_spec + let name = get(opts, 'as', fnamemodify(repo, ':t:s?\.git$??')) + let spec = extend(s:infer_properties(name, repo), opts) if !has_key(g:plugs, name) call add(g:plugs_order, name) endif @@ -515,16 +563,22 @@ function! s:syntax() syn match plugStar /^*/ syn match plugMessage /\(^- \)\@<=.*/ syn match plugName /\(^- \)\@<=[^ ]*:/ + syn match plugSha /\%(: \)\@<=[0-9a-z]\{4,}$/ + syn match plugTag /(tag: [^)]\+)/ syn match plugInstall /\(^+ \)\@<=[^:]*/ syn match plugUpdate /\(^* \)\@<=[^:]*/ - syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha - syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained + syn match plugCommit /^ \X*[0-9a-z]\{7} .*/ contains=plugRelDate,plugEdge,plugTag + syn match plugEdge /^ \X\+$/ + syn match plugEdge /^ \X*/ contained nextgroup=plugSha + syn match plugSha /[0-9a-z]\{7}/ contained syn match plugRelDate /([^)]*)$/ contained syn match plugNotLoaded /(not loaded)$/ syn match plugError /^x.*/ + syn match plugH2 /^.*:\n-\+$/ syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean hi def link plug1 Title hi def link plug2 Repeat + hi def link plugH2 Type hi def link plugX Exception hi def link plugBracket Structure hi def link plugNumber Number @@ -540,7 +594,9 @@ function! s:syntax() hi def link plugError Error hi def link plugRelDate Comment + hi def link plugEdge PreProc hi def link plugSha Identifier + hi def link plugTag Constant hi def link plugNotLoaded Comment endfunction @@ -599,32 +655,45 @@ function! s:switch_out(...) endif endfunction -function! s:prepare() +function! s:finish_bindings() + nnoremap R :silent! call retry() + nnoremap D :PlugDiff + nnoremap S :PlugStatus + nnoremap U :call status_update() + xnoremap U :call status_update() + nnoremap ]] :silent! call section('') + nnoremap [[ :silent! call section('b') +endfunction + +function! s:prepare(...) + if empty(getcwd()) + throw 'Invalid current working directory. Cannot proceed.' + endif + call s:job_abort() if s:switch_in() - silent %d _ - else - call s:new_window() - nnoremap q :if b:plug_preview==1pcendifechoq - nnoremap R :silent! call retry() - nnoremap D :PlugDiff - nnoremap S :PlugStatus - nnoremap U :call status_update() - xnoremap U :call status_update() - nnoremap ]] :silent! call section('') - nnoremap [[ :silent! call section('b') - let b:plug_preview = -1 - let s:plug_tab = tabpagenr() - let s:plug_buf = winbufnr(0) - call s:assign_name() + normal q endif + + call s:new_window() + nnoremap q :if b:plug_preview==1pcendifbd + if a:0 == 0 + call s:finish_bindings() + endif + let b:plug_preview = -1 + let s:plug_tab = tabpagenr() + let s:plug_buf = winbufnr(0) + call s:assign_name() + silent! unmap silent! unmap L silent! unmap o silent! unmap X setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable setf vim-plug - call s:syntax() + if exists('g:syntax_on') + call s:syntax() + endif endfunction function! s:assign_name() @@ -646,10 +715,11 @@ function! s:do(pull, force, todo) endif let installed = has_key(s:update.new, name) let updated = installed ? 0 : - \ (a:pull && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir))) + \ (a:pull && index(s:update.errors, name) < 0 && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir))) if a:force || installed || updated execute 'cd' s:esc(spec.dir) call append(3, '- Post-update hook for '. name .' ... ') + let error = '' let type = type(spec.do) if type == s:TYPE.string try @@ -658,26 +728,60 @@ function! s:do(pull, force, todo) let g:_plug_do = '!'.escape(spec.do, '#!%') execute "normal! :execute g:_plug_do\\" finally - let result = v:shell_error ? ('Exit status: '.v:shell_error) : 'Done!' + if v:shell_error + let error = 'Exit status: ' . v:shell_error + endif unlet g:_plug_do endtry elseif type == s:TYPE.funcref try let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged') call spec.do({ 'name': name, 'status': status, 'force': a:force }) - let result = 'Done!' catch - let result = 'Error: ' . v:exception + let error = v:exception endtry else - let result = 'Error: Invalid type!' + let error = 'Invalid hook type' endif - call setline(4, getline(4) . result) + call setline(4, empty(error) ? (getline(4) . 'OK') + \ : ('x' . getline(4)[1:] . error)) cd - endif endfor endfunction +function! s:hash_match(a, b) + return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0 +endfunction + +function! s:checkout(plugs) + for [name, spec] in items(a:plugs) + let sha = spec.commit + call append(3, '- Checking out '.sha[:6].' of '.name.' ... ') + redraw + + let error = [] + let output = s:lines(s:system('git rev-parse HEAD', spec.dir)) + if v:shell_error + let error = output + elseif !s:hash_match(sha, output[0]) + let output = s:lines(s:system( + \ 'git fetch --depth 999999 && git checkout '.sha, spec.dir)) + if v:shell_error + let error = output + endif + endif + if empty(error) + call setline(4, getline(4) . 'OK') + else + call setline(4, 'x'.getline(4)[1:] . 'Error') + for line in reverse(error) + call append(4, ' '.line) + endfor + endif + endfor +endfunction + function! s:finish(pull) let new_frozen = len(filter(keys(s:update.new), 'g:plugs[v:val].frozen')) if new_frozen @@ -699,6 +803,7 @@ function! s:finish(pull) call add(msgs, "Press 'D' to see the updated changes.") endif echo join(msgs, ' ') + call s:finish_bindings() endfunction function! s:retry() @@ -720,7 +825,7 @@ endfunction function! s:update_impl(pull, force, args) abort let args = copy(a:args) let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ? - \ remove(args, -1) : get(g:, 'plug_threads', s:is_win ? 1 : 16) + \ remove(args, -1) : get(g:, 'plug_threads', 16) let managed = filter(copy(g:plugs), 's:is_managed(v:key)') let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') : @@ -757,9 +862,8 @@ function! s:update_impl(pull, force, args) abort echohl None endif - let python = (has('python') || has('python3')) && !s:is_win && !has('win32unix') - \ && (!s:nvim || has('vim_starting')) - let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) + let python = (has('python') || has('python3')) && (!s:nvim || has('vim_starting')) + let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) let s:update = { \ 'start': reltime(), @@ -774,7 +878,7 @@ function! s:update_impl(pull, force, args) abort \ 'fin': 0 \ } - call s:prepare() + call s:prepare(1) call append(0, ['', '']) normal! 2G silent! redraw @@ -785,7 +889,7 @@ function! s:update_impl(pull, force, args) abort " Python version requirement (>= 2.7) if python && !has('python3') && !ruby && !s:nvim && s:update.threads > 1 redir => pyv - silent python import platform; print(platform.python_version()) + silent python import platform; print platform.python_version() redir END let python = s:version_requirement( \ map(split(split(pyv)[0], '\.'), 'str2nr(v:val)'), [2, 6]) @@ -832,6 +936,7 @@ function! s:update_finish() let $GIT_TERMINAL_PROMPT = s:git_terminal_prompt endif if s:switch_in() + call s:checkout(filter(copy(s:update.all), 'has_key(v:val, "commit")')) call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'has_key(v:val, "do")')) call s:finish(s:update.pull) call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.') @@ -861,7 +966,13 @@ function! s:job_handler(job_id, data, event) abort endif if a:event == 'stdout' - let self.result .= substitute(s:to_s(a:data), '[\r\n]', '', 'g') . "\n" + let complete = empty(a:data[-1]) + let lines = map(filter(a:data, 'len(v:val) > 0'), 'split(v:val, "[\r\n]")[-1]') + call extend(self.lines, lines) + let self.result = join(self.lines, "\n") + if !complete + call remove(self.lines, -1) + endif " To reduce the number of buffer updates let self.tick = get(self, 'tick', -1) + 1 if self.tick % len(s:jobs) == 0 @@ -878,7 +989,7 @@ function! s:job_handler(job_id, data, event) abort endfunction function! s:spawn(name, cmd, opts) - let job = { 'name': a:name, 'running': 1, 'error': 0, 'result': '', + let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [], 'result': '', \ 'new': get(a:opts, 'new', 0), \ 'on_stdout': function('s:job_handler'), \ 'on_exit' : function('s:job_handler'), @@ -986,8 +1097,8 @@ while 1 " Without TCO, Vim stack is bound to explode let merge = s:shellesc(has_tag ? spec.tag : 'origin/'.spec.branch) if !new - let [valid, msg] = s:git_valid(spec, 0) - if valid + let error = s:git_validate(spec, 0) + if empty(error) if pull let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : '' call s:spawn(name, @@ -997,7 +1108,7 @@ while 1 " Without TCO, Vim stack is bound to explode let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 } endif else - let s:jobs[name] = { 'running': 0, 'result': msg, 'error': 1 } + let s:jobs[name] = { 'running': 0, 'result': error, 'error': 1 } endif else call s:spawn(name, @@ -1019,9 +1130,8 @@ endwhile endfunction function! s:update_python() -let py_exe = has('python3') ? 'python3' : 'python' +let py_exe = has('python') ? 'python' : 'python3' execute py_exe "<< EOF" -""" Due to use of signals this function is POSIX only. """ import datetime import functools import os @@ -1048,33 +1158,29 @@ G_CLONE_OPT = vim.eval('s:clone_opt') G_PROGRESS = vim.eval('s:progress_opt(1)') G_LOG_PROB = 1.0 / int(vim.eval('s:update.threads')) G_STOP = thr.Event() -G_THREADS = {} +G_IS_WIN = vim.eval('s:is_win') == '1' -class BaseExc(Exception): +class PlugError(Exception): def __init__(self, msg): - self._msg = msg - @property - def msg(self): - return self._msg -class CmdTimedOut(BaseExc): + self.msg = msg +class CmdTimedOut(PlugError): pass -class CmdFailed(BaseExc): +class CmdFailed(PlugError): pass -class InvalidURI(BaseExc): +class InvalidURI(PlugError): pass class Action(object): INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-'] class Buffer(object): - def __init__(self, lock, num_plugs, is_pull, is_win): + def __init__(self, lock, num_plugs, is_pull): self.bar = '' self.event = 'Updating' if is_pull else 'Installing' - self.is_win = is_win self.lock = lock self.maxy = int(vim.eval('winheight(".")')) self.num_plugs = num_plugs - def _where(self, name): + def __where(self, name): """ Find first line with name in current buffer. Return line num. """ found, lnum = False, 0 matcher = re.compile('^[-+x*] {0}:'.format(name)) @@ -1097,14 +1203,12 @@ class Buffer(object): with self.lock: vim.command('normal! 2G') - if not self.is_win: - vim.command('redraw') + vim.command('redraw') def write(self, action, name, lines): first, rest = lines[0], lines[1:] msg = ['{0} {1}{2}{3}'.format(action, name, ': ' if first else '', first)] - padded_rest = [' ' + line for line in rest] - msg.extend(padded_rest) + msg.extend([' ' + line for line in rest]) try: if action == Action.ERROR: @@ -1114,7 +1218,7 @@ class Buffer(object): self.bar += '=' curbuf = vim.current.buffer - lnum = self._where(name) + lnum = self.__where(name) if lnum != -1: # Found matching line num del curbuf[lnum] if lnum > self.maxy and action in set([Action.INSTALL, Action.UPDATE]): @@ -1128,62 +1232,84 @@ class Buffer(object): pass class Command(object): - def __init__(self, cmd, cmd_dir=None, timeout=60, ntries=3, cb=None, clean=None): - self.cmd = cmd - self.cmd_dir = cmd_dir - self.timeout = timeout - self.ntries = ntries - self.callback = cb if cb else (lambda msg: None) - self.clean = clean + CD = 'cd /d' if G_IS_WIN else 'cd' - def attempt_cmd(self): - """ Tries to run the command, returns result if no exceptions. """ - attempt = 0 - finished = False - limit = self.timeout + def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None): + self.cmd = cmd + if cmd_dir: + self.cmd = '{0} {1} && {2}'.format(Command.CD, cmd_dir, self.cmd) + self.timeout = timeout + self.callback = cb if cb else (lambda msg: None) + self.clean = clean if clean else (lambda: None) + self.proc = None + + @property + def alive(self): + """ Returns true only if command still running. """ + return self.proc and self.proc.poll() is None + + def execute(self, ntries=3): + """ Execute the command with ntries if CmdTimedOut. + Returns the output of the command if no Exception. + """ + attempt, finished, limit = 0, False, self.timeout while not finished: try: attempt += 1 - result = self.timeout_cmd() + result = self.try_command() finished = True + return result except CmdTimedOut: - if attempt != self.ntries: - for count in range(3, 0, -1): - if G_STOP.is_set(): - raise KeyboardInterrupt - msg = 'Timeout. Will retry in {0} second{1} ...'.format( - count, 's' if count != 1 else '') - self.callback([msg]) - time.sleep(1) + if attempt != ntries: + self.notify_retry() self.timeout += limit - self.callback(['Retrying ...']) else: raise - return result + def notify_retry(self): + """ Retry required for command, notify user. """ + for count in range(3, 0, -1): + if G_STOP.is_set(): + raise KeyboardInterrupt + msg = 'Timeout. Will retry in {0} second{1} ...'.format( + count, 's' if count != 1 else '') + self.callback([msg]) + time.sleep(1) + self.callback(['Retrying ...']) - def timeout_cmd(self): + def try_command(self): """ Execute a cmd & poll for callback. Returns list of output. - Raises CmdFailed -> return code for Popen isn't 0 - Raises CmdTimedOut -> command exceeded timeout without new output + Raises CmdFailed -> return code for Popen isn't 0 + Raises CmdTimedOut -> command exceeded timeout without new output """ - proc = None first_line = True - try: - tfile = tempfile.NamedTemporaryFile(mode='w+b', delete=False) - proc = subprocess.Popen(self.cmd, cwd=self.cmd_dir, stdout=tfile, - stderr=subprocess.STDOUT, shell=True, preexec_fn=os.setsid) - while proc.poll() is None: - # Yield this thread - time.sleep(0.2) + try: + tfile = tempfile.NamedTemporaryFile(mode='w+b') + preexec_fn = not G_IS_WIN and os.setsid or None + self.proc = subprocess.Popen(self.cmd, stdout=tfile, + stderr=subprocess.STDOUT, + stdin=subprocess.PIPE, shell=True, + preexec_fn=preexec_fn) + thrd = thr.Thread(target=(lambda proc: proc.wait()), args=(self.proc,)) + thrd.start() + + thread_not_started = True + while thread_not_started: + try: + thrd.join(0.1) + thread_not_started = False + except RuntimeError: + pass + + while self.alive: if G_STOP.is_set(): raise KeyboardInterrupt if first_line or random.random() < G_LOG_PROB: first_line = False - line = nonblock_read(tfile.name) + line = '' if G_IS_WIN else nonblock_read(tfile.name) if line: self.callback([line]) @@ -1191,23 +1317,27 @@ class Command(object): if time_diff > self.timeout: raise CmdTimedOut(['Timeout!']) + thrd.join(0.5) + tfile.seek(0) result = [line.decode('utf-8', 'replace').rstrip() for line in tfile] - if proc.returncode != 0: - msg = [''] - msg.extend(result) - raise CmdFailed(msg) - except: - if proc and proc.poll() is None: - os.killpg(proc.pid, signal.SIGTERM) - if self.clean: - self.clean() - raise - finally: - os.remove(tfile.name) + if self.proc.returncode != 0: + raise CmdFailed([''] + result) - return result + return result + except: + self.terminate() + raise + + def terminate(self): + """ Terminate process and cleanup. """ + if self.alive: + if G_IS_WIN: + os.kill(self.proc.pid, signal.SIGINT) + else: + os.killpg(self.proc.pid, signal.SIGTERM) + self.clean() class Plugin(object): def __init__(self, name, args, buf_q, lock): @@ -1228,7 +1358,7 @@ class Plugin(object): self.install() with self.lock: thread_vim_command("let s:update.new['{0}'] = 1".format(self.name)) - except (CmdTimedOut, CmdFailed, InvalidURI) as exc: + except PlugError as exc: self.write(Action.ERROR, self.name, exc.msg) except KeyboardInterrupt: G_STOP.set() @@ -1241,6 +1371,8 @@ class Plugin(object): def install(self): target = self.args['dir'] + if target[-1] == '\\': + target = target[0:-1] def clean(target): def _clean(): @@ -1253,11 +1385,18 @@ class Plugin(object): self.write(Action.INSTALL, self.name, ['Installing ...']) callback = functools.partial(self.write, Action.INSTALL, self.name) cmd = 'git clone {0} {1} --recursive {2} -b {3} {4} 2>&1'.format( - '' if self.tag else G_CLONE_OPT, G_PROGRESS, self.args['uri'], self.checkout, esc(target)) - com = Command(cmd, None, G_TIMEOUT, G_RETRIES, callback, clean(target)) - result = com.attempt_cmd() + '' if self.tag else G_CLONE_OPT, G_PROGRESS, self.args['uri'], + self.checkout, esc(target)) + com = Command(cmd, None, G_TIMEOUT, callback, clean(target)) + result = com.execute(G_RETRIES) self.write(Action.DONE, self.name, result[-1:]) + def repo_uri(self): + cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url' + command = Command(cmd, self.args['dir'], G_TIMEOUT,) + result = command.execute(G_RETRIES) + return result[-1] + def update(self): match = re.compile(r'git::?@') actual_uri = re.sub(match, '', self.repo_uri()) @@ -1278,18 +1417,12 @@ class Plugin(object): 'git merge --ff-only {0}'.format(self.merge), 'git submodule update --init --recursive'] cmd = ' 2>&1 && '.join(cmds) - com = Command(cmd, self.args['dir'], G_TIMEOUT, G_RETRIES, callback) - result = com.attempt_cmd() + com = Command(cmd, self.args['dir'], G_TIMEOUT, callback) + result = com.execute(G_RETRIES) self.write(Action.DONE, self.name, result[-1:]) else: self.write(Action.DONE, self.name, ['Already installed']) - def repo_uri(self): - cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url' - command = Command(cmd, self.args['dir'], G_TIMEOUT, G_RETRIES) - result = command.attempt_cmd() - return result[-1] - def write(self, action, name, msg): self.buf_q.put((action, name, msg)) @@ -1311,10 +1444,6 @@ class PlugThread(thr.Thread): work_q.task_done() except queue.Empty: pass - finally: - global G_THREADS - with lock: - del G_THREADS[thr.current_thread().name] class RefreshThread(thr.Thread): def __init__(self, lock): @@ -1326,7 +1455,7 @@ class RefreshThread(thr.Thread): while self.running: with self.lock: thread_vim_command('noautocmd normal! a') - time.sleep(0.2) + time.sleep(0.33) def stop(self): self.running = False @@ -1360,25 +1489,23 @@ def main(): nthreads = int(vim.eval('s:update.threads')) plugs = vim.eval('s:update.todo') mac_gui = vim.eval('s:mac_gui') == '1' - is_win = vim.eval('s:is_win') == '1' lock = thr.Lock() - buf = Buffer(lock, len(plugs), G_PULL, is_win) + buf = Buffer(lock, len(plugs), G_PULL) buf_q, work_q = queue.Queue(), queue.Queue() for work in plugs.items(): work_q.put(work) - global G_THREADS + start_cnt = thr.active_count() for num in range(nthreads): tname = 'PlugT-{0:02}'.format(num) thread = PlugThread(tname, (buf_q, work_q, lock)) thread.start() - G_THREADS[tname] = thread if mac_gui: rthread = RefreshThread(lock) rthread.start() - while not buf_q.empty() or len(G_THREADS) != 0: + while not buf_q.empty() or thr.active_count() != start_cnt: try: action, name, msg = buf_q.get(True, 0.25) buf.write(action, name, msg) @@ -1421,16 +1548,20 @@ function! s:update_ruby() def killall pid pids = [pid] - unless `which pgrep 2> /dev/null`.empty? - children = pids - until children.empty? - children = children.map { |pid| - `pgrep -P #{pid}`.lines.map { |l| l.chomp } - }.flatten - pids += children + if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM + pids.each { |pid| Process.kill 'INT', pid.to_i rescue nil } + else + unless `which pgrep 2> /dev/null`.empty? + children = pids + until children.empty? + children = children.map { |pid| + `pgrep -P #{pid}`.lines.map { |l| l.chomp } + }.flatten + pids += children + end end + pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } end - pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } end require 'thread' @@ -1456,7 +1587,7 @@ function! s:update_ruby() $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})" $curbuf[2] = '[' + bar.ljust(tot) + ']' VIM::command('normal! 2G') - VIM::command('redraw') unless iswin + VIM::command('redraw') } where = proc { |name| (1..($curbuf.length)).find { |l| $curbuf[l] =~ /^[-+x*] #{name}:/ } } log = proc { |name, result, type| @@ -1568,8 +1699,8 @@ function! s:update_ruby() exists = File.directory? dir ok, result = if exists - dir = iswin ? dir : esc(dir) - ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil + chdir = "#{cd} #{iswin ? dir : esc(dir)}" + ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil current_uri = data.lines.to_a.last if !ret if data =~ /^Interrupted|^Timeout/ @@ -1585,7 +1716,7 @@ function! s:update_ruby() if pull log.call name, 'Updating ...', :update fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : '' - bt.call "#{cd} #{dir} && git fetch #{fetch_opt} #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm}", name, :update, nil + bt.call "#{chdir} && git fetch #{fetch_opt} #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm}", name, :update, nil else [true, skip] end @@ -1615,7 +1746,7 @@ function! s:shellesc(arg) endfunction function! s:glob_dir(path) - return map(filter(s:lines(globpath(a:path, '**')), 'isdirectory(v:val)'), 's:dirpath(v:val)') + return map(filter(s:glob(a:path, '**'), 'isdirectory(v:val)'), 's:dirpath(v:val)') endfunction function! s:progress_bar(line, bar, total) @@ -1659,42 +1790,46 @@ function! s:system_chomp(...) return v:shell_error ? '' : substitute(ret, '\n$', '', '') endfunction -function! s:git_valid(spec, check_branch) - let ret = 1 - let msg = 'OK' +function! s:git_validate(spec, check_branch) + let err = '' if isdirectory(a:spec.dir) let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url', a:spec.dir)) let remote = result[-1] if v:shell_error - let msg = join([remote, 'PlugClean required.'], "\n") - let ret = 0 + let err = join([remote, 'PlugClean required.'], "\n") elseif !s:compare_git_uri(remote, a:spec.uri) - let msg = join(['Invalid URI: '.remote, + let err = join(['Invalid URI: '.remote, \ 'Expected: '.a:spec.uri, \ 'PlugClean required.'], "\n") - let ret = 0 + elseif a:check_branch && has_key(a:spec, 'commit') + let result = s:lines(s:system('git rev-parse HEAD 2>&1', a:spec.dir)) + let sha = result[-1] + if v:shell_error + let err = join(add(result, 'PlugClean required.'), "\n") + elseif !s:hash_match(sha, a:spec.commit) + let err = join([printf('Invalid HEAD (expected: %s, actual: %s)', + \ a:spec.commit[:6], sha[:6]), + \ 'PlugUpdate required.'], "\n") + endif elseif a:check_branch let branch = result[0] " Check tag if has_key(a:spec, 'tag') let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir) if a:spec.tag !=# tag - let msg = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', + let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', \ (empty(tag) ? 'N/A' : tag), a:spec.tag) - let ret = 0 endif " Check branch elseif a:spec.branch !=# branch - let msg = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', + let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', \ branch, a:spec.branch) - let ret = 0 endif endif else - let msg = 'Not found' - let ret = 0 + let err = 'Not found' endif - return [ret, msg] + return err endfunction function! s:rm_rf(dir) @@ -1712,7 +1847,7 @@ function! s:clean(force) let dirs = [] let [cnt, total] = [0, len(g:plugs)] for [name, spec] in items(g:plugs) - if !s:is_managed(name) || s:git_valid(spec, 0)[0] + if !s:is_managed(name) || empty(s:git_validate(spec, 0)) call add(dirs, spec.dir) endif let cnt += 1 @@ -1746,10 +1881,7 @@ function! s:clean(force) if empty(todo) call append(line('$'), 'Already clean.') else - call inputsave() - let yes = a:force || (input('Proceed? (y/N) ') =~? '^y') - call inputrestore() - if yes + if a:force || s:ask('Proceed?') for dir in todo call s:rm_rf(dir) endfor @@ -1805,7 +1937,8 @@ function! s:status() for [name, spec] in items(g:plugs) if has_key(spec, 'uri') if isdirectory(spec.dir) - let [valid, msg] = s:git_valid(spec, 1) + let err = s:git_validate(spec, 1) + let [valid, msg] = [empty(err), empty(err) ? 'OK' : err] else let [valid, msg] = [0, 'Not found. Try PlugInstall.'] endif @@ -1890,7 +2023,7 @@ function! s:preview_commit() let b:plug_preview = !s:is_preview_window_open() endif - let sha = matchstr(getline('.'), '\(^ \)\@<=[0-9a-z]\{7}') + let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-z]\{7}') if empty(sha) return endif @@ -1914,41 +2047,72 @@ function! s:section(flags) call search('\(^[x-] \)\@<=[^:]\+:', a:flags) endfunction +function! s:format_git_log(line) + let indent = ' ' + let tokens = split(a:line, nr2char(1)) + if len(tokens) != 5 + return indent.substitute(a:line, '\s*$', '', '') + endif + let [graph, sha, refs, subject, date] = tokens + let tag = matchstr(refs, 'tag: [^,)]\+') + let tag = empty(tag) ? ' ' : ' ('.tag.') ' + return printf('%s%s%s%s%s (%s)', indent, graph, sha, tag, subject, date) +endfunction + +function! s:append_ul(lnum, text) + call append(a:lnum, ['', a:text, repeat('-', len(a:text))]) +endfunction + function! s:diff() call s:prepare() - call append(0, 'Collecting updated changes ...') - normal! gg - redraw - - let cnt = 0 - for [k, v] in items(g:plugs) - if !isdirectory(v.dir) || !s:is_managed(k) + call append(0, ['Collecting changes ...', '']) + let cnts = [0, 0] + let bar = '' + let total = filter(copy(g:plugs), 's:is_managed(v:key) && isdirectory(v:val.dir)') + call s:progress_bar(2, bar, len(total)) + for origin in [1, 0] + let plugs = reverse(sort(items(filter(copy(total), (origin ? '' : '!').'(has_key(v:val, "commit") || has_key(v:val, "tag"))')))) + if empty(plugs) continue endif - - let diff = s:system_chomp('git log --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"', v.dir) - if !empty(diff) - call append(1, '') - call append(2, '- '.k.':') - call append(3, map(s:lines(diff), '" ". v:val')) - let cnt += 1 - normal! gg + call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:') + for [k, v] in plugs + let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..' + let diff = s:system_chomp('git log --graph --color=never --pretty=format:"%x01%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir) + if !empty(diff) + let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' + call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) + let cnts[origin] += 1 + endif + let bar .= '=' + call s:progress_bar(2, bar, len(total)) + normal! 2G redraw + endfor + if !cnts[origin] + call append(5, ['', 'N/A']) endif endfor + call setline(1, printf('%d plugin(s) updated.', cnts[0]) + \ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : '')) - call setline(1, cnt == 0 ? 'No updates.' : 'Last update:') - nnoremap :silent! call preview_commit() - nnoremap o :silent! call preview_commit() - nnoremap X :call revert() - normal! gg - setlocal nomodifiable - if cnt > 0 + if cnts[0] || cnts[1] + nnoremap :silent! call preview_commit() + nnoremap o :silent! call preview_commit() + endif + if cnts[0] + nnoremap X :call revert() echo "Press 'X' on each block to revert the update" endif + normal! gg + setlocal nomodifiable endfunction function! s:revert() + if search('^Pending updates', 'bnW') + return + endif + let name = s:find_name(line('.')) if empty(name) || !has_key(g:plugs, name) || \ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y' @@ -1962,42 +2126,35 @@ function! s:revert() echo 'Reverted.' endfunction -function! s:snapshot(...) abort - let home = get(s:, 'plug_home_org', g:plug_home) - let [type, var, header] = s:is_win ? - \ ['dosbatch', '%PLUG_HOME%', - \ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '', - \ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.home]] : - \ ['sh', '$PLUG_HOME', - \ ['#!/bin/sh', '# Generated by vim-plug', '# '.strftime("%c"), '', - \ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]] - +function! s:snapshot(force, ...) abort call s:prepare() - execute 'setf' type - call append(0, header) - call append('$', '') + setf vim + call append(0, ['" Generated by vim-plug', + \ '" '.strftime("%c"), + \ '" :source this file in vim to restore the snapshot', + \ '" or execute: vim -S snapshot.vim', + \ '', '', 'PlugUpdate!']) 1 - redraw - - let dirs = sort(map(values(filter(copy(g:plugs), - \'has_key(v:val, "uri") && isdirectory(v:val.dir)')), 'v:val.dir')) - let anchor = line('$') - 1 - for dir in reverse(dirs) - let sha = s:system_chomp('git rev-parse --short HEAD', dir) + let anchor = line('$') - 3 + let names = sort(keys(filter(copy(g:plugs), + \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)'))) + for name in reverse(names) + let sha = s:system_chomp('git rev-parse --short HEAD', g:plugs[name].dir) if !empty(sha) - call append(anchor, printf('cd %s && git reset --hard %s', - \ substitute(dir, '^\V'.escape(g:plug_home, '\'), var, ''), sha)) + call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha)) redraw endif endfor if a:0 > 0 let fn = expand(a:1) - let fne = s:esc(fn) + if filereadable(fn) && !(a:force || s:ask(a:1.' already exists. Overwrite?')) + return + endif call writefile(getline(1, '$'), fn) - if !s:is_win | call s:system('chmod +x ' . fne) | endif - echo 'Saved to '.a:1 - silent execute 'e' fne + echo 'Saved as '.a:1 + silent execute 'e' s:esc(fn) + setf vim endif endfunction diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 94b1a7a..e9f63ee 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -6,7 +6,7 @@ Plug 'morhetz/gruvbox' Plug 'Yggdroot/indentLine' Plug 'scrooloose/nerdtree' Plug 'godlygeek/tabular' -Plug 'majutsushi/tagbar' +" Plug 'majutsushi/tagbar' Plug 'tomtom/tcomment_vim' Plug 'bling/vim-airline' Plug 'tommcdo/vim-exchange' @@ -17,15 +17,21 @@ Plug 'MarcWeber/vim-addon-mw-utils' Plug 'tomtom/tlib_vim' Plug 'SirVer/ultisnips' Plug 'honza/vim-snippets' -Plug 'beyondmarc/glsl.vim' +" Plug 'beyondmarc/glsl.vim' Plug 'tpope/vim-dispatch' -Plug 'freitass/todo.txt-vim' +" Plug 'freitass/todo.txt-vim' Plug 'tpope/vim-unimpaired' Plug 'milkypostman/vim-togglelist' Plug 'Valloric/YouCompleteMe' +" Plug 'Shougo/deoplete.nvim' +" Plug 'vim-scripts/LanguageTool' +" Plug 'pangloss/vim-javascript' +Plug 'moll/vim-bbye' +Plug 'tpope/vim-fugitive' +Plug 'tikhomirov/vim-glsl' call plug#end() -let g:ctrlp_custom_ignore = '\v[\/](bin|obj)$' +let g:ctrlp_custom_ignore = '\v[\/](bin|docs)$' let delimitMate_expand_cr = 1 @@ -35,14 +41,15 @@ set t_ZH= set t_ZR= set background=dark -let g:indentLine_char = '│' -let g:indentLine_color_term = 239 +" let g:indentLine_char = '│' +" let g:indentLine_color_term = 239 +set list lcs=tab:\│\ " map :NERDTreeToggle map :NERDTreeToggle " map :TagbarToggle -map :TagbarToggle +" map :TagbarToggle let g:airline_powerline_fonts = 1 let g:airline#extensions#tabline#enabled = 1 @@ -76,6 +83,7 @@ set number set relativenumber set laststatus=2 set softtabstop=4 +set tabstop=4 set shiftwidth=4 set noexpandtab set completeopt-=preview @@ -83,6 +91,9 @@ set completeopt-=preview " I do not remember what this is for " set cinkeys=0{,0},0),:,!^F,o,O,e +let g:languagetool_jar='$HOME/.local/bin/LanguageTool-3.2/languagetool-commandline.jar' +let g:languagetool_lang="nl" + map :bn map :bp @@ -93,13 +104,19 @@ autocmd FileType cpp map :Make autocmd FileType cpp map :Make debug autocmd FileType cpp map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . +autocmd FileType go let &makeprg="go run %:p:h/*.go" +autocmd FileType go map :Make + autocmd FileType tex map :!arara % +if !filereadable(expand("%:p:h")."/Makefile") + let &makeprg="cd CMake/default && make" +endif map :call ToggleQuickfixList() map :e ./todo/todo.txt map :e ./todo/done.txt -map :grep -F TODO -R ./src/**/*.cpp ./include/**/*.h :cw -map :grep -F NOTE -R ./src/**/*.cpp ./include/**/*.h :cw +" map :grep -F TODO -R ./src/**/*.cpp ./include/**/*.h :cw +" map :grep -F NOTE -R ./src/**/*.cpp ./include/**/*.h :cw function! NeatFoldText() let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' ' @@ -112,7 +129,45 @@ function! NeatFoldText() return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend endfunction -set foldtext=NeatFoldText() +function! MyFoldText() " {{{ + let line = getline(v:foldstart) + + let nucolwidth = &fdc + &number * &numberwidth + let windowwidth = winwidth(0) - nucolwidth - 3 + let foldedlinecount = v:foldend - v:foldstart + + " expand tabs into spaces + let onetab = strpart(' ', 0, &tabstop) + let line = substitute(line, '\t', onetab, 'g') + + let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) + let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' +endfunction " }}} + +fu! CustomFoldText() + "get first non-blank line + let fs = v:foldstart + while getline(fs) =~ '^\s*$' | let fs = nextnonblank(fs + 1) + endwhile + if fs > v:foldend + let line = getline(v:foldstart) + else + let line = substitute(getline(fs), '\t', repeat(' ', &tabstop), 'g') + endif + + let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0) + let foldSize = 1 + v:foldend - v:foldstart + let foldSizeStr = " " . foldSize . " lines " + let foldLevelStr = repeat("+--", v:foldlevel) + let lineCount = line("$") + let foldPercentage = printf("[%.1f", (foldSize*1.0)/lineCount*100) . "%] " + let expansionString = repeat(".", w - strwidth(foldSizeStr.line.foldLevelStr.foldPercentage)) + return line . expansionString . foldSizeStr . foldPercentage . foldLevelStr +endf + +" set foldtext=NeatFoldText() +set foldtext=CustomFoldText() set foldcolumn=1 -au BufRead *.cpp setlocal foldmethod=syntax -au BufRead *.cpp setlocal foldnestmax=1 +au BufRead *.cpp,*.go,*.js setlocal foldmethod=syntax +au BufRead *.cpp,*go,*.js setlocal foldnestmax=1 diff --git a/nvim/.config/nvim/plugged/LanguageTool b/nvim/.config/nvim/plugged/LanguageTool new file mode 160000 index 0000000..e4f234b --- /dev/null +++ b/nvim/.config/nvim/plugged/LanguageTool @@ -0,0 +1 @@ +Subproject commit e4f234b8a06e2d855e3ddcee1e9d81d203830c63 diff --git a/nvim/.config/nvim/plugged/YouCompleteMe b/nvim/.config/nvim/plugged/YouCompleteMe index 0352ed9..cb57569 160000 --- a/nvim/.config/nvim/plugged/YouCompleteMe +++ b/nvim/.config/nvim/plugged/YouCompleteMe @@ -1 +1 @@ -Subproject commit 0352ed9b1f8f6bb4b9cdc1c164b564573243aecc +Subproject commit cb5756943fdd3ba062f101a5aba34acdd34d1356 diff --git a/nvim/.config/nvim/plugged/ctrlp-py-matcher b/nvim/.config/nvim/plugged/ctrlp-py-matcher index 9e84cf8..8a80326 160000 --- a/nvim/.config/nvim/plugged/ctrlp-py-matcher +++ b/nvim/.config/nvim/plugged/ctrlp-py-matcher @@ -1 +1 @@ -Subproject commit 9e84cf8072866b92faf5082cb93a554b75e35fd0 +Subproject commit 8a803267a741cff3d6147650745f83c8f2125578 diff --git a/nvim/.config/nvim/plugged/ctrlp.vim b/nvim/.config/nvim/plugged/ctrlp.vim index b5d3fe6..564176f 160000 --- a/nvim/.config/nvim/plugged/ctrlp.vim +++ b/nvim/.config/nvim/plugged/ctrlp.vim @@ -1 +1 @@ -Subproject commit b5d3fe66a58a13d2ff8b6391f4387608496a030f +Subproject commit 564176f01d7f3f7f8ab452ff4e1f5314de7b0981 diff --git a/nvim/.config/nvim/plugged/deoplete.nvim b/nvim/.config/nvim/plugged/deoplete.nvim new file mode 160000 index 0000000..816bea3 --- /dev/null +++ b/nvim/.config/nvim/plugged/deoplete.nvim @@ -0,0 +1 @@ +Subproject commit 816bea3a9a0c5a1cc53488256d452edea04cb70a diff --git a/nvim/.config/nvim/plugged/glsl.vim b/nvim/.config/nvim/plugged/glsl.vim index 9bc625e..245c525 160000 --- a/nvim/.config/nvim/plugged/glsl.vim +++ b/nvim/.config/nvim/plugged/glsl.vim @@ -1 +1 @@ -Subproject commit 9bc625e4d5fc8cee40dfa9e811aa210e5dba945f +Subproject commit 245c52580408e8eaae178ce11735498034c0dab7 diff --git a/nvim/.config/nvim/plugged/gruvbox b/nvim/.config/nvim/plugged/gruvbox index e4ba7ab..91bae68 160000 --- a/nvim/.config/nvim/plugged/gruvbox +++ b/nvim/.config/nvim/plugged/gruvbox @@ -1 +1 @@ -Subproject commit e4ba7abe5ccccc0ebea0e33a4e045f96311020d8 +Subproject commit 91bae6876031ececf151cc4f28aa5fb8c93681e4 diff --git a/nvim/.config/nvim/plugged/indentLine b/nvim/.config/nvim/plugged/indentLine index 6011a61..2a26173 160000 --- a/nvim/.config/nvim/plugged/indentLine +++ b/nvim/.config/nvim/plugged/indentLine @@ -1 +1 @@ -Subproject commit 6011a6132c40d7f8fecadd7b44677f539289ea4c +Subproject commit 2a2617310b0fb4c0daf02be2ba465fada257f2d0 diff --git a/nvim/.config/nvim/plugged/nerdtree b/nvim/.config/nvim/plugged/nerdtree index 0b44415..35c8591 160000 --- a/nvim/.config/nvim/plugged/nerdtree +++ b/nvim/.config/nvim/plugged/nerdtree @@ -1 +1 @@ -Subproject commit 0b44415a3302030b56755cc1135ca9ca57dc1ada +Subproject commit 35c859179da4ad4f96eb8255e428904436a0b4b4 diff --git a/nvim/.config/nvim/plugged/tcomment_vim b/nvim/.config/nvim/plugged/tcomment_vim index c067932..7c42777 160000 --- a/nvim/.config/nvim/plugged/tcomment_vim +++ b/nvim/.config/nvim/plugged/tcomment_vim @@ -1 +1 @@ -Subproject commit c067932263fbb8add3c330485b14f31f791418f0 +Subproject commit 7c4277754b6b77fb80b47cd4a7384d1e2d6c1538 diff --git a/nvim/.config/nvim/plugged/tlib_vim b/nvim/.config/nvim/plugged/tlib_vim index 04b1b1d..34b1329 160000 --- a/nvim/.config/nvim/plugged/tlib_vim +++ b/nvim/.config/nvim/plugged/tlib_vim @@ -1 +1 @@ -Subproject commit 04b1b1de812f521a88e42df387695c5c6378eac2 +Subproject commit 34b13299b5da7ad66ea387027d458bd54127687c diff --git a/nvim/.config/nvim/plugged/todo.txt-vim b/nvim/.config/nvim/plugged/todo.txt-vim index b3d9e18..1e3a5e5 160000 --- a/nvim/.config/nvim/plugged/todo.txt-vim +++ b/nvim/.config/nvim/plugged/todo.txt-vim @@ -1 +1 @@ -Subproject commit b3d9e18b081bfdfeec50af58fa7eb5a353a10675 +Subproject commit 1e3a5e58aeb4aa508ce2e36bcb5230452812c4c3 diff --git a/nvim/.config/nvim/plugged/ultisnips b/nvim/.config/nvim/plugged/ultisnips index c9699fe..3c420ed 160000 --- a/nvim/.config/nvim/plugged/ultisnips +++ b/nvim/.config/nvim/plugged/ultisnips @@ -1 +1 @@ -Subproject commit c9699feed1cc301826fdb36ad3bb37e14be1d4ea +Subproject commit 3c420ed63f54a3359d5bc4e500cb9abd0c9177c5 diff --git a/nvim/.config/nvim/plugged/vim-airline b/nvim/.config/nvim/plugged/vim-airline index 14d14cf..eaf2034 160000 --- a/nvim/.config/nvim/plugged/vim-airline +++ b/nvim/.config/nvim/plugged/vim-airline @@ -1 +1 @@ -Subproject commit 14d14cf951c08fc88ca6c3e6f28fe47b99421e23 +Subproject commit eaf2034163b9b9dab2217d10c48ae0d52e90d07b diff --git a/nvim/.config/nvim/plugged/vim-bbye b/nvim/.config/nvim/plugged/vim-bbye new file mode 160000 index 0000000..a018cbc --- /dev/null +++ b/nvim/.config/nvim/plugged/vim-bbye @@ -0,0 +1 @@ +Subproject commit a018cbc1ba63b1a8b86b7c468645e7642637ec4a diff --git a/nvim/.config/nvim/plugged/vim-dispatch b/nvim/.config/nvim/plugged/vim-dispatch index 69fea41..fc8d1e6 160000 --- a/nvim/.config/nvim/plugged/vim-dispatch +++ b/nvim/.config/nvim/plugged/vim-dispatch @@ -1 +1 @@ -Subproject commit 69fea418692f76058d5cd95f0a17ed6b0f5bbb77 +Subproject commit fc8d1e68cd58fb3ffdd56109bf855cda92b10b70 diff --git a/nvim/.config/nvim/plugged/vim-fugitive b/nvim/.config/nvim/plugged/vim-fugitive new file mode 160000 index 0000000..bdd2168 --- /dev/null +++ b/nvim/.config/nvim/plugged/vim-fugitive @@ -0,0 +1 @@ +Subproject commit bdd216827ae53cdf70d933bb30762da9bf42cad4 diff --git a/nvim/.config/nvim/plugged/vim-glsl b/nvim/.config/nvim/plugged/vim-glsl new file mode 160000 index 0000000..6ea4e19 --- /dev/null +++ b/nvim/.config/nvim/plugged/vim-glsl @@ -0,0 +1 @@ +Subproject commit 6ea4e1983b18cf440c8f800a3e94b57338a3e99f diff --git a/nvim/.config/nvim/plugged/vim-javascript b/nvim/.config/nvim/plugged/vim-javascript new file mode 160000 index 0000000..1d8c267 --- /dev/null +++ b/nvim/.config/nvim/plugged/vim-javascript @@ -0,0 +1 @@ +Subproject commit 1d8c2677d26d6b3950b90dc1636e63334c8efc3b diff --git a/nvim/.config/nvim/plugged/vim-javascript-syntax b/nvim/.config/nvim/plugged/vim-javascript-syntax new file mode 160000 index 0000000..9e019fc --- /dev/null +++ b/nvim/.config/nvim/plugged/vim-javascript-syntax @@ -0,0 +1 @@ +Subproject commit 9e019fccd738ba73713268a327ac3765646a4edd diff --git a/nvim/.config/nvim/plugged/vim-snippets b/nvim/.config/nvim/plugged/vim-snippets index 8cb1d88..042aec6 160000 --- a/nvim/.config/nvim/plugged/vim-snippets +++ b/nvim/.config/nvim/plugged/vim-snippets @@ -1 +1 @@ -Subproject commit 8cb1d88e475ac3c109f56ebd5379c07d3ed83a9f +Subproject commit 042aec6f06e958d74f072855bfd365a671aaf49b diff --git a/nvim/.config/nvim/plugged/vim-tmux-navigator b/nvim/.config/nvim/plugged/vim-tmux-navigator index 754871f..eaa5289 160000 --- a/nvim/.config/nvim/plugged/vim-tmux-navigator +++ b/nvim/.config/nvim/plugged/vim-tmux-navigator @@ -1 +1 @@ -Subproject commit 754871fc6e523133921cb4f72b26111ff61cd7dd +Subproject commit eaa5289b5161ef2c24fb66364ad563ea4ef5b170 diff --git a/nvim/.config/nvim/plugged/vim-unimpaired b/nvim/.config/nvim/plugged/vim-unimpaired index 23f471a..11dc568 160000 --- a/nvim/.config/nvim/plugged/vim-unimpaired +++ b/nvim/.config/nvim/plugged/vim-unimpaired @@ -1 +1 @@ -Subproject commit 23f471ad0f00e2fab097f9d67ffd770881d4b35a +Subproject commit 11dc568dbfd7a56866a4354c737515769f08e9fe diff --git a/nvim/.config/nvim/plugged/vim-z80 b/nvim/.config/nvim/plugged/vim-z80 new file mode 160000 index 0000000..3b9e2b2 --- /dev/null +++ b/nvim/.config/nvim/plugged/vim-z80 @@ -0,0 +1 @@ +Subproject commit 3b9e2b28582fbad167100e950602ccbc67cbdf39 diff --git a/scripts/config_gen.py b/scripts/config_gen.py new file mode 100755 index 0000000..e2a6176 --- /dev/null +++ b/scripts/config_gen.py @@ -0,0 +1,456 @@ +#!/usr/bin/env python2 + +import sys +import os +import os.path +import re +import argparse +import datetime +import multiprocessing +import shlex +import shutil +import tempfile +import time +import subprocess +import glob + + +# Default flags for make +default_make_flags = ["-i", "-j" + str(multiprocessing.cpu_count())] + +# Set YCM-Generator directory +# Always obtain the real path to the directory where 'config_gen.py' lives as, +# in some cases, it will be a symlink placed in '/usr/bin' (as is the case +# with the Arch Linux AUR package) and it won't +# be able to find the plugin directory. +ycm_generator_dir = os.path.dirname(os.path.realpath(__file__)) + + +def main(): + # parse command-line args + parser = argparse.ArgumentParser(description="Automatically generates config files for YouCompleteMe") + parser.add_argument("-v", "--verbose", action="store_true", help="Show output from build process") + parser.add_argument("-m", "--make", default="make", help="Use the specified executable for make.") + parser.add_argument("-c", "--compiler", help="Use the specified executable for clang. It should be the same version as the libclang used by YCM. The executable for clang++ will be inferred from this.") + parser.add_argument("-C", "--configure_opts", default="", help="Additional flags to pass to configure/cmake/etc. e.g. --configure_opts=\"--enable-FEATURE\"") + parser.add_argument("-F", "--format", choices=["ycm", "cc"], default="ycm", help="Format of output file (YouCompleteMe or color_coded). Default: ycm") + parser.add_argument("-M", "--make-flags", help="Flags to pass to make when fake-building. Default: -M=\"{}\"".format(" ".join(default_make_flags))) + parser.add_argument("-o", "--output", help="Save the config file as OUTPUT. Default: .ycm_extra_conf.py, or .color_coded if --format=cc.") + parser.add_argument("-x", "--language", choices=["c", "c++"], help="Only output flags for the given language. This defaults to whichever language has its compiler invoked the most.") + parser.add_argument("--out-of-tree", action="store_true", help="Build autotools projects out-of-tree. This is a no-op for other project types.") + parser.add_argument("--qt-version", choices=["4", "5"], default="5", help="Use the given Qt version for qmake. (Default: 5)") + parser.add_argument("-e", "--preserve-environment", action="store_true", help="Pass environment variables to build processes.") + parser.add_argument("PROJECT_DIR", help="The root directory of the project.") + args = vars(parser.parse_args()) + project_dir = os.path.abspath(args["PROJECT_DIR"]) + + # verify that project_dir exists + if(not os.path.exists(project_dir)): + print("ERROR: '{}' does not exist".format(project_dir)) + return 1 + + # verify the clang is installed, and infer the correct name for both the C and C++ compilers + try: + cc = args["compiler"] or "clang" + args["cc"] = subprocess.check_output(["which", cc]).strip() + except subprocess.CalledProcessError: + print("ERROR: Could not find clang at '{}'. Please make sure it is installed and is either in your path, or specified with --compiler.".format(cc)) + return 1 + + try: + h, t = os.path.split(args["compiler"] or "clang") + cxx = os.path.join(h, t.replace("clang", "clang++")) + args["cxx"] = subprocess.check_output(["which", cxx]).strip() + except subprocess.CalledProcessError: + print("ERROR: Could not find clang++ at '{}'. Please make sure it is installed and specified appropriately.".format(cxx)) + return 1 + + # sanity check - remove this after we add Windows support + if(sys.platform.startswith("win32")): + print("ERROR: Windows is not supported") + + # prompt user to overwrite existing file (if necessary) + config_file = { + None: args["output"], + "cc": os.path.join(project_dir, ".color_coded"), + "ycm": os.path.join(project_dir, ".ycm_extra_conf.py"), + }[args["format"] if args["output"] is None else None] + + if(os.path.exists(config_file)): + print("'{}' already exists. Overwrite? [y/N] ".format(config_file)), + response = sys.stdin.readline().strip().lower() + + if(response != "y" and response != "yes"): + return 1 + + # command-line args to pass to fake_build() using kwargs + args["make_cmd"] = args.pop("make") + args["configure_opts"] = shlex.split(args["configure_opts"]) + args["make_flags"] = default_make_flags if args["make_flags"] is None else shlex.split(args["make_flags"]) + force_lang = args.pop("language") + output_format = args.pop("format") + del args["compiler"] + del args["output"] + del args["PROJECT_DIR"] + + generate_conf = { + "ycm": generate_ycm_conf, + "cc": generate_cc_conf, + }[output_format] + + # temporary files to hold build logs + with tempfile.NamedTemporaryFile(mode="rw") as c_build_log: + with tempfile.NamedTemporaryFile(mode="rw") as cxx_build_log: + # perform the actual compilation of flags + fake_build(project_dir, c_build_log.name, cxx_build_log.name, **args) + (c_count, c_skip, c_flags) = parse_flags(c_build_log) + (cxx_count, cxx_skip, cxx_flags) = parse_flags(cxx_build_log) + + print("Collected {} relevant entries for C compilation ({} discarded).".format(c_count, c_skip)) + print("Collected {} relevant entries for C++ compilation ({} discarded).".format(cxx_count, cxx_skip)) + + # select the language to compile for. If -x was used, zero all other options (so we don't need to repeat the error code) + if(force_lang == "c"): + cxx_count = 0 + elif(force_lang == "c++"): + c_count = 0 + + if(c_count == 0 and cxx_count == 0): + print() + print("ERROR: No commands were logged to the build logs (C: {}, C++: {}).".format(c_build_log.name, cxx_build_log.name)) + print("Your build system may not be compatible.") + c_build_log.delete = False + cxx_build_log.delete = False + return 3 + + elif(c_count > cxx_count): + lang, flags = ("c", c_flags) + else: + lang, flags = ("c++", cxx_flags) + + generate_conf(["-x", lang] + flags, config_file) + print("Created {} config file with {} {} flags".format(output_format.upper(), len(flags), lang.upper())) + + +def fake_build(project_dir, c_build_log_path, cxx_build_log_path, verbose, make_cmd, cc, cxx, out_of_tree, configure_opts, make_flags, preserve_environment, qt_version): + '''Builds the project using the fake toolchain, to collect the compiler flags. + + project_dir: the directory containing the source files + build_log_path: the file to log commands to + verbose: show the build process output + make_cmd: the path of the make executable + cc: the path of the clang executable + cxx: the path of the clang++ executable + out_of_tree: perform an out-of-tree build (autotools only) + configure_opts: additional flags for configure stage + make_flags: additional flags for make + preserve_environment: pass environment variables to build processes + qt_version: The Qt version to use when building with qmake. + ''' + + # TODO: add Windows support + assert(not sys.platform.startswith("win32")) + fake_path = os.path.join(ycm_generator_dir, "fake-toolchain", "Unix") + + # environment variables and arguments for build process + started = time.time() + FNULL = open(os.devnull, "w") + proc_opts = {} if verbose else { + "stdin": FNULL, + "stdout": FNULL, + "stderr": FNULL + } + proc_opts["cwd"] = project_dir + + if(preserve_environment): + env = os.environ + else: + # Preserve HOME, since Cmake needs it to find some packages and it's + # normally there anyway. See #26. + env = dict(map(lambda x: (x, os.environ[x]), ["HOME"])) + + env["PATH"] = "{}:{}".format(fake_path, os.environ["PATH"]) + env["CC"] = "clang" + env["CXX"] = "clang++" + env["YCM_CONFIG_GEN_CC_LOG"] = c_build_log_path + env["YCM_CONFIG_GEN_CXX_LOG"] = cxx_build_log_path + + # used during configuration stage, so that cmake, etc. can verify what the compiler supports + env_config = env.copy() + env_config["YCM_CONFIG_GEN_CC_PASSTHROUGH"] = cc + env_config["YCM_CONFIG_GEN_CXX_PASSTHROUGH"] = cxx + + # use -i (ignore errors), since the makefile may include scripts which + # depend upon the existence of various output files + make_args = [make_cmd] + make_flags + + # Used for the qmake build system below + pro_files = glob.glob(os.path.join(project_dir, "*.pro")) + + # sanity check - make sure the toolchain is available + assert os.path.exists(fake_path), "Could not find toolchain at '{}'".format(fake_path) + + # helper function to display exact commands used + def run(cmd, *args, **kwargs): + print("$ " + " ".join(cmd)) + subprocess.call(cmd, *args, **kwargs) + + # execute the build system + if(os.path.exists(os.path.join(project_dir, "CMakeLists.txt"))): + # cmake + # run cmake in a temporary directory, then compile the project as usual + build_dir = tempfile.mkdtemp() + proc_opts["cwd"] = build_dir + + # if the project was built in-tree, we need to hide the cache file so that cmake + # populates the build dir instead of just re-generating the existing files + cache_path = os.path.join(project_dir, "CMakeCache.txt") + + if(os.path.exists(cache_path)): + fd, cache_tmp = tempfile.mkstemp() + os.close(fd) + shutil.move(cache_path, cache_tmp) + else: + cache_tmp = None + + print("Running cmake in '{}'...".format(build_dir)) + run(["cmake", project_dir] + configure_opts, env=env_config, **proc_opts) + + print("\nRunning make...") + run(make_args, env=env, **proc_opts) + + print("\nCleaning up...") + print("") + shutil.rmtree(build_dir) + + if(cache_tmp): + shutil.move(cache_tmp, cache_path) + + elif(os.path.exists(os.path.join(project_dir, "configure"))): + # autotools + # perform build in-tree, since not all projects handle out-of-tree builds correctly + + if(out_of_tree): + build_dir = tempfile.mkdtemp() + proc_opts["cwd"] = build_dir + print("Configuring autotools in '{}'...".format(build_dir)) + else: + print("Configuring autotools...") + + run([os.path.join(project_dir, "configure")] + configure_opts, env=env_config, **proc_opts) + + print("\nRunning make...") + run(make_args, env=env, **proc_opts) + + print("\nCleaning up...") + + if(out_of_tree): + print("") + shutil.rmtree(build_dir) + else: + run([make_cmd, "maintainer-clean"], env=env, **proc_opts) + + elif(pro_files): + # qmake + # make sure there is only one .pro file + if len(pro_files) != 1: + print("ERROR: Found {} .pro files (expected one): {}.".format( + len(pro_files), ', '.join(pro_files))) + sys.exit(1) + + # run qmake in a temporary directory, then compile the project as usual + build_dir = tempfile.mkdtemp() + proc_opts["cwd"] = build_dir + env_config["QT_SELECT"] = qt_version + env_config["QMAKESPEC"] = "unsupported/linux-clang" if qt_version == "4" else "linux-clang" + + print("Running qmake in '{}' with Qt {}...".format(build_dir, qt_version)) + run(["qmake"] + configure_opts + [pro_files[0]], env=env_config, + **proc_opts) + + print("\nRunning make...") + run(make_args, env=env, **proc_opts) + + print("\nCleaning up...") + print("") + shutil.rmtree(build_dir) + + elif(any([os.path.exists(os.path.join(project_dir, x)) for x in ["GNUmakefile", "makefile", "Makefile"]])): + # make + # needs to be handled last, since other build systems can generate Makefiles + print("Preparing build directory...") + run([make_cmd, "clean"], env=env, **proc_opts) + + print("\nRunning make...") + run(make_args, env=env, **proc_opts) + + else: + print("ERROR: Unknown build system") + sys.exit(2) + + print("Build completed in {} sec".format(round(time.time() - started, 2))) + print("") + + +def parse_flags(build_log): + '''Creates a list of compiler flags from the build log. + + build_log: an iterator of lines + Returns: (line_count, skip_count, flags) + flags is a list, and the counts are integers + ''' + + # Used to ignore entries which result in temporary files, or don't fully + # compile the file + temp_output = re.compile("(-x assembler)|(-o ([a-zA-Z0-9._].tmp))|(/dev/null)") + skip_count = 0 + + # Flags we want: + # -includes (-i, -I) + # -defines (-D) + # -warnings (-Werror), but no assembler, etc. flags (-Wa,-option) + # -language (-std=gnu99) and standard library (-nostdlib) + # -word size (-m64) + flags_whitelist = ["-[iID].*", "-W[^,]*", "-std=[a-z0-9+]+", "-(no)?std(lib|inc)", "-m[0-9]+"] + flags_whitelist = re.compile("|".join(map("^{}$".format, flags_whitelist))) + flags = set() + line_count = 0 + + # macro definitions should be handled separately, so we can resolve duplicates + define_flags = dict() + define_regex = re.compile("-D([a-zA-Z0-9_]+)=(.*)") + + # Used to only bundle filenames with applicable arguments + filename_flags = ["-o", "-I", "-isystem", "-include", "-imacros"] + + # Process build log + for line in build_log: + if(temp_output.search(line)): + skip_count += 1 + continue + + line_count += 1 + words = split_flags(line) + + for (i, word) in enumerate(words): + if(word[0] != '-' or not flags_whitelist.match(word)): + continue + + # handle macro definitions + m = define_regex.match(word) + if(m): + if(m.group(1) not in define_flags): + define_flags[m.group(1)] = [m.group(2)] + elif(m.group(2) not in define_flags[m.group(1)]): + define_flags[m.group(1)].append(m.group(2)) + + continue + + # include arguments for this option, if there are any, as a tuple + if(i != len(words) - 1 and word in filename_flags and words[i + 1][0] != '-'): + flags.add((word, words[i + 1])) + else: + flags.add(word) + + # Only specify one word size (the largest) + # (Different sizes are used for different files in the linux kernel.) + mRegex = re.compile("^-m[0-9]+$") + word_flags = list([f for f in flags if isinstance(f, basestring) and mRegex.match(f)]) + + if(len(word_flags) > 1): + for flag in word_flags: + flags.remove(flag) + + flags.add(max(word_flags)) + + # Resolve duplicate macro definitions (always choose the last value for consistency) + for name, values in define_flags.iteritems(): + if(len(values) > 1): + print("WARNING: {} distinct definitions of macro {} found".format(len(values), name)) + values.sort() + + flags.add("-D{}={}".format(name, values[0])) + + return (line_count, skip_count, sorted(flags)) + + +def generate_cc_conf(flags, config_file): + '''Generates the .color_coded file + + flags: the list of flags + config_file: the path to save the configuration file at''' + + with open(config_file, "w") as output: + for flag in flags: + if(isinstance(flag, basestring)): + output.write(flag + "\n") + else: # is tuple + for f in flag: + output.write(f + "\n") + + +def generate_ycm_conf(flags, config_file): + '''Generates the .ycm_extra_conf.py. + + flags: the list of flags + config_file: the path to save the configuration file at''' + + template_file = os.path.join(ycm_generator_dir, "template.py") + + with open(template_file, "r") as template: + with open(config_file, "w") as output: + output.write("# Generated by YCM Generator at {}\n\n".format(str(datetime.datetime.today()))) + + for line in template: + if(line == " # INSERT FLAGS HERE\n"): + # insert generated code + for flag in flags: + if(isinstance(flag, basestring)): + output.write(" '{}',\n".format(flag)) + else: # is tuple + output.write(" '{}', '{}',\n".format(*flag)) + + else: + # copy template + output.write(line) + + +def split_flags(line): + '''Helper method that splits a string into flags. + Flags are space-seperated, except for spaces enclosed in quotes. + Returns a list of flags''' + + # Pass 1: split line using whitespace + words = line.strip().split() + + # Pass 2: merge words so that the no. of quotes is balanced + res = [] + + for w in words: + if(len(res) > 0 and unbalanced_quotes(res[-1])): + res[-1] += " " + w + else: + res.append(w) + + return res + + +def unbalanced_quotes(s): + '''Helper method that returns True if the no. of single or double quotes in s is odd.''' + + single = 0 + double = 0 + + for c in s: + if(c == "'"): + single += 1 + elif(c == '"'): + double += 1 + + return (single % 2 == 1 or double % 2 == 1) + + +if(__name__ == "__main__"): + # Note that sys.exit() lets us use None and 0 interchangably + sys.exit(main()) + diff --git a/scripts/fake-toolchain/Unix/ar b/scripts/fake-toolchain/Unix/ar new file mode 120000 index 0000000..f32a580 --- /dev/null +++ b/scripts/fake-toolchain/Unix/ar @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/as b/scripts/fake-toolchain/Unix/as new file mode 120000 index 0000000..f32a580 --- /dev/null +++ b/scripts/fake-toolchain/Unix/as @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/cc b/scripts/fake-toolchain/Unix/cc new file mode 100755 index 0000000..9a321b6 --- /dev/null +++ b/scripts/fake-toolchain/Unix/cc @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ ! -z "$YCM_CONFIG_GEN_CC_PASSTHROUGH" ]; then + # Cmake determines compiler properties by compiling a test file, so call clang for this case + $YCM_CONFIG_GEN_CC_PASSTHROUGH $@ + +elif [ "$1" = "-v" ] || [ "$1" = "--version" ]; then + # Needed to enable clang-specific options for certain build systems (e.g. linux) + $YCM_CONFIG_GEN_CC_PASSTHROUGH $@ + +else + echo "$@" >> $YCM_CONFIG_GEN_CC_LOG +fi + diff --git a/scripts/fake-toolchain/Unix/clang b/scripts/fake-toolchain/Unix/clang new file mode 120000 index 0000000..2652f5f --- /dev/null +++ b/scripts/fake-toolchain/Unix/clang @@ -0,0 +1 @@ +cc \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/clang++ b/scripts/fake-toolchain/Unix/clang++ new file mode 120000 index 0000000..34836c6 --- /dev/null +++ b/scripts/fake-toolchain/Unix/clang++ @@ -0,0 +1 @@ +cxx \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/cxx b/scripts/fake-toolchain/Unix/cxx new file mode 100755 index 0000000..06cdf0e --- /dev/null +++ b/scripts/fake-toolchain/Unix/cxx @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ ! -z "$YCM_CONFIG_GEN_CC_PASSTHROUGH" ]; then + # Cmake determines compiler properties by compiling a test file, so call clang for this case + $YCM_CONFIG_GEN_CXX_PASSTHROUGH $@ + +elif [ "$1" = "-v" ] || [ "$1" = "--version" ]; then + # Needed to enable clang-specific options for certain build systems (e.g. linux) + $YCM_CONFIG_GEN_CC_PASSTHROUGH $@ + +else + echo "$@" >> $YCM_CONFIG_GEN_CXX_LOG +fi + diff --git a/scripts/fake-toolchain/Unix/g++ b/scripts/fake-toolchain/Unix/g++ new file mode 120000 index 0000000..34836c6 --- /dev/null +++ b/scripts/fake-toolchain/Unix/g++ @@ -0,0 +1 @@ +cxx \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/gcc b/scripts/fake-toolchain/Unix/gcc new file mode 120000 index 0000000..2652f5f --- /dev/null +++ b/scripts/fake-toolchain/Unix/gcc @@ -0,0 +1 @@ +cc \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/gcc++ b/scripts/fake-toolchain/Unix/gcc++ new file mode 120000 index 0000000..34836c6 --- /dev/null +++ b/scripts/fake-toolchain/Unix/gcc++ @@ -0,0 +1 @@ +cxx \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/ld b/scripts/fake-toolchain/Unix/ld new file mode 120000 index 0000000..f32a580 --- /dev/null +++ b/scripts/fake-toolchain/Unix/ld @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/nm b/scripts/fake-toolchain/Unix/nm new file mode 120000 index 0000000..f32a580 --- /dev/null +++ b/scripts/fake-toolchain/Unix/nm @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/scripts/fake-toolchain/Unix/true b/scripts/fake-toolchain/Unix/true new file mode 100755 index 0000000..420376f --- /dev/null +++ b/scripts/fake-toolchain/Unix/true @@ -0,0 +1,4 @@ +#!/bin/sh +# This script is needed because /bin/true does not exist on non-FHS-compliant distros. e.g. NixOS +exit 0 + diff --git a/scripts/spacey b/scripts/spacey index c39164a..0854299 100755 --- a/scripts/spacey +++ b/scripts/spacey @@ -35,5 +35,4 @@ cat << EOF $f7 ▄█▄ $rst $f7▄█████████▄$rst $f7▀▀▀▀▀▀▀▀▀▀▀$rst - EOF diff --git a/scripts/template.py b/scripts/template.py new file mode 100644 index 0000000..28c0d29 --- /dev/null +++ b/scripts/template.py @@ -0,0 +1,134 @@ +# This file is NOT licensed under the GPLv3, which is the license for the rest +# of YouCompleteMe. +# +# Here's the license text for this file: +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# 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 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. +# +# For more information, please refer to + +import os +import ycm_core + +flags = [ + # INSERT FLAGS HERE +] + + +# Set this to the absolute path to the folder (NOT the file!) containing the +# compile_commands.json file to use that instead of 'flags'. See here for +# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html +# +# You can get CMake to generate this file for you by adding: +# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) +# to your CMakeLists.txt file. +# +# Most projects will NOT need to set this to anything; you can just change the +# 'flags' list of compilation flags. Notice that YCM itself uses that approach. +compilation_database_folder = '' + +if os.path.exists( compilation_database_folder ): + database = ycm_core.CompilationDatabase( compilation_database_folder ) +else: + database = None + +SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] + +def DirectoryOfThisScript(): + return os.path.dirname( os.path.abspath( __file__ ) ) + + +def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): + if not working_directory: + return list( flags ) + new_flags = [] + make_next_absolute = False + path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] + for flag in flags: + new_flag = flag + + if make_next_absolute: + make_next_absolute = False + if not flag.startswith( '/' ): + new_flag = os.path.join( working_directory, flag ) + + for path_flag in path_flags: + if flag == path_flag: + make_next_absolute = True + break + + if flag.startswith( path_flag ): + path = flag[ len( path_flag ): ] + new_flag = path_flag + os.path.join( working_directory, path ) + break + + if new_flag: + new_flags.append( new_flag ) + return new_flags + + +def IsHeaderFile( filename ): + extension = os.path.splitext( filename )[ 1 ] + return extension in [ '.h', '.hxx', '.hpp', '.hh' ] + + +def GetCompilationInfoForFile( filename ): + # The compilation_commands.json file generated by CMake does not have entries + # for header files. So we do our best by asking the db for flags for a + # corresponding source file, if any. If one exists, the flags for that file + # should be good enough. + if IsHeaderFile( filename ): + basename = os.path.splitext( filename )[ 0 ] + for extension in SOURCE_EXTENSIONS: + replacement_file = basename + extension + if os.path.exists( replacement_file ): + compilation_info = database.GetCompilationInfoForFile( + replacement_file ) + if compilation_info.compiler_flags_: + return compilation_info + return None + return database.GetCompilationInfoForFile( filename ) + + +def FlagsForFile( filename, **kwargs ): + if database: + # Bear in mind that compilation_info.compiler_flags_ does NOT return a + # python list, but a "list-like" StringVec object + compilation_info = GetCompilationInfoForFile( filename ) + if not compilation_info: + return None + + final_flags = MakeRelativePathsInFlagsAbsolute( + compilation_info.compiler_flags_, + compilation_info.compiler_working_dir_ ) + + else: + relative_to = DirectoryOfThisScript() + final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) + + return { + 'flags': final_flags, + 'do_cache': True + } + diff --git a/scripts/watchfile b/scripts/watchfile new file mode 100755 index 0000000..3baf4e0 --- /dev/null +++ b/scripts/watchfile @@ -0,0 +1,206 @@ +#!/bin/bash + +version=1.0.1 +versionDate="2014-02-14" + +function showHelp() { +echo "watchfile - monitor file(s)/command and perform action when changed + +Possible ways of usage +---------------------------------------- +Monitor FILE, when modified execute FILE +\$ watchfile [options] FILE + +Monitor FILE, when modified execute CMND [PARAM_1 ..PARAM_N] +\$ watchfile [options] FILE CMND [PARAM_1 .. PARAM_N] + +Monitor FILE_1 .. FILE_N, when modified execute CMND [PARAM_1 ..PARAM_N] +\$ watchfile [options] -i FILE_1 .. FILE_N -e CMND [PARAM_1 .. PARAM_N] + +Monitor output of CMND1, when modified execute CMND2 [PARAM_1 .. PARAM_N] +\$ watchfile [options] -s \"CMND1\" -e CMND [PARAM_1 .. PARAM_N] + + +options: +-h, --help Show help +-d, --delay=N Specify the delay between each monitor update. Default 0.5. +--check-content If set it checks file content, instead of just the timestamp. + Has no effect with the -s flag set. +--no-clear If set, it doesn't clear the screen before executing CMND. +-v, --version Outputs version information + +flags: +-s, Next argument specifies monitor command. Requires -e flag. +-i, Start listing files to monitor. Requires -e flag. +-e, Start listing command to execute. Requires -s or -i or flag. + Must be the last flag used (CMND can thus use flags as parameters) + +Note: If CMND isn't found, and ./CMND is, it automatically uses this command. +Note: If the command uses ampersands (&, &&), these must be escaped (\&, \&\&). + + +Examples +---------------------------------------- +Monitor executable foo.sh, and execute on change +$ watchfile foo.sh + +Monitor python file foo.py, and execute it on change +$ watchfile foo.py python foo.py + +As above, but monitor content (not just timestamp): +$ watchfile --check-content foo.py python foo.py + +Compiling main.cpp file on change: +$ watchfile main.cpp g++ -Wall main.cpp -o main + +Compiling main.cpp file on change, running when compilation succeedes: +$ watchfile main.cpp g++ -Wall main.cpp -o main \&\& ./main + +Compiling project whenever source files changes, and running if it succeedes: +$ watchfile -s \"find . -name '*.cpp' -or -name '*.h' | xargs cat\" \\ + -e make \&\& ./main + +See: http://swarminglogic.com/jotting/2014_02_watchfile for more examples + +Mainted at: https://gist.github.com/swarminglogic/8963507 +Author: Roald Fernandez (github@swarminglogic.com) +Version: $version ($versionDate) +License: CC-zero (public domain) +" + exit $1 +} + +function parseParameters() { + tmp=$@ + leftovers="" + while test $# -gt 0; do + case "$1" in + -h|--help) + showHelp 0 + ;; + --no-clear) + shift + flagNoClear=true + ;; + --check-content) + shift + flagCheckContent=true + ;; + -d) + shift + delay=$1 + shift + ;; + --delay*) + delay=`echo $1 | sed -e 's/^[^=]*=//g'` + shift + ;; + -v|--version) + shift + echo "watchfile $version" + exit 0 + ;; + -s) + shift + flagS=true + watchcmnd=$1 + shift + ;; + -i) + shift + flagI=true + nI=0 + for i in `seq 1 $#`; do + if [[ ${!i} == -* ]] ; then + break; + else + ((++nI)) + fi + done + watchfiles=${@:1:$nI} + shift $nI + ;; + -e) + shift + flagE=true + execcmnd=${@:1} + break + ;; + -*) + leftovers="$leftovers "$1 + shift + ;; + *) + leftovers="$leftovers "$1 + shift + ;; + esac + done + if [[ $flagE && (! $flagS) && (! $flagI) ]] ; then + echo "Error: If -e flag is set, -s or -i flags are required." + exit 1 + elif [[ ($flagS || $flagI) && ! $flagE ]] ; then + echo "Error: If -s or -i flags are set, the -e flags is required." + exit 1 + elif [[ $flagS && $flagI ]]; then + echo "Error: Both -s and -i flags cannot be used simultaneously." + exit 1 + elif [[ (! $flagE) && (! $flagS) && (! $flagI) ]] ; then + set -- $leftovers + watchfiles=$1 + if [ $# -gt 1 ]; then + execcmnd=${@:2} + else + execcmnd=$watchfiles + fi + fi +} + +# Exit with help if no parameters +if [[ ! $@ ]] ; then showHelp 1; fi + +# Defaults +delay=0.5 + +# Parse parameters into $watch and $execcmnd variables +parseParameters "$@" + +# Sanitize executable +set -- $execcmnd +if [[ ! `which $1` ]] && [[ -x ./$1 ]] ; then + execcmnd=./$execcmnd +elif [[ ! `which $1` ]] && [[ ! -x ./$1 ]] ; then + echo "Error: No executable $1 or ./$1 found" + exit 1 +fi + +# Main monitoring loop. +if [[ -z $watchcmnd ]] ; then + if [[ ! $flagCheckContent ]] ; then + watchcmnd="stat -c %Y $watchfiles | md5sum" + else + watchcmnd="cat $watchfiles | md5sum" + fi +else + watchcmnd="$watchcmnd | md5sum" +fi + +md5sum=`eval $watchcmnd` +md5sumNow=$md5sum +while [[ true ]] +do + # Loop until some files have changed + while [[ "$md5sumNow" = "$md5sum" ]] + do + sleep $delay + md5sumNow=`eval $watchcmnd` + done + + # Execute the file, as it has changed. + if [[ ! $flagNoClear ]] ; then + clear + fi + eval $execcmnd + + md5sum=$md5sumNow +done diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index 744b59b..96dc1f3 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -35,7 +35,6 @@ set -g status-right-attr "none" set -g message-fg "colour246" set -g message-command-bg "colour239" set -g status-attr "none" -set -g status-utf8 "on" set -g pane-border-fg "colour239" set -g status-left-attr "none" setw -g window-status-fg "colour246" diff --git a/zsh/.zshrc b/zsh/.zshrc index 3e8f14c..07cdc29 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -7,11 +7,11 @@ setopt correct source $ZSH/oh-my-zsh.sh #setting environment variables -export EDITOR=vim +export EDITOR=nvim export ABSROOT=$HOME/Projects/abs export PATH="/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" export PATH="$HOME/.local/bin:$PATH" -export PATH="$HOME/.local/bin/scripts:$PATH" +export PATH="$HOME/.local/bin/scripts:$PATH:/usr/bin/core_perl" export TERM="screen-256color" export SAL_USE_VCLPLUGIN="gtk" export GOPATH="$HOME/.local/go" @@ -22,7 +22,7 @@ alias cl="clear" alias vim="nvim" alias tmux="tmux -2" alias attach="tmux a" -alias wcp="wc -l src/**/*.cpp include/**/*.h" +alias wcp="wc -l **/src/**/*.cpp **/include/**/*.h" #start tmux if [ -z "$TMUX" ]; then tmux; exit; fi