-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d15123a
commit 6102020
Showing
3 changed files
with
57 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
let s:autoload_root = expand('<sfile>:p:h:h') | ||
let s:git_dir = simplify(expand('<sfile>:p:h:h:h') . '/.git') | ||
|
||
function! s:get_git_commit() abort | ||
if !executable('git') || !isdirectory(s:git_dir) | ||
return 'UNKNOWN' | ||
endif | ||
|
||
let l:git = 'git --git-dir=' . shellescape(s:git_dir) . ' ' | ||
let l:commit = system(l:git . 'rev-parse HEAD') | ||
let l:is_dirty = system(l:git . 'status --porcelain') =~? '\S' | ||
|
||
return l:commit . (l:is_dirty ? ' (dirty)' : '') | ||
endfunction | ||
|
||
function! async#embedder#embed(...) abort | ||
let l:args = {} | ||
|
||
for l:arg in a:000 | ||
let l:idx = stridx(l:arg, '=') | ||
let l:key = l:arg[:l:idx - 1] | ||
let l:value = l:arg[l:idx + 1:] | ||
let l:args[l:key] = l:value | ||
endfor | ||
|
||
if !has_key(l:args, 'path') | ||
echom 'path required' | ||
return | ||
endif | ||
|
||
if !has_key(l:args, 'namespace') | ||
echom 'namespace required' | ||
endif | ||
|
||
|
||
let l:lines = readfile(s:autoload_root . '/async/job.vim') | ||
let l:lines = map(l:lines, {_, l -> substitute(l, '\V\C\<async#job', l:args['namespace'], 'g')}) | ||
|
||
let l:content = [ | ||
\ printf('" https://github.com/prabirshrestha/async.vim#%s', s:get_git_commit()), | ||
\ '" :AsyncEmbed ' . join(a:000, ' '), | ||
\ '', | ||
\ ] | ||
|
||
let l:content += l:lines | ||
call mkdir(fnamemodify(l:args['path'], ':h'), 'p') | ||
call writefile(l:content, l:args['path']) | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if exists('g:async_vim') | ||
finish | ||
endif | ||
let g:async_vim = 1 | ||
|
||
" :AsyncEmbed path=./autoload/myplugin/job.vim namespace=myplugin#job | ||
command! -nargs=+ AsyncEmbed :call async#embedder#embed(<f-args>) |