diff --git a/README.md b/README.md index 2c02722..3551606 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,11 @@ vimwiki-sync ============ -This is a fork of [vimwiki-sync](https://github.com/RollMan/vimwiki-sync/), the -original plugin *automatically* synchronised Vimwiki notes into a local git -repository, with all changed files being automatically committed. This fork -provides several improvements. These include: +This is a fork of [vimwiki-sync](https://github.com/jerryyin/vimwiki-sync) +without external dependencies. -* Fully handle all supported (configured) extension and wiki paths -* Refactored vimscript -* Asynchronous operations (depends on [vim-dispatch](https://github.com/tpope/vim-dispatch), and your personal `sync.sh` in notes directory) - - -### A sample of `sync.sh` +## Install -```bash -#!/bin/bash +Add `Plug 'icalvin102/vimwiki-sync'` to your .vimrc -gstatus=`git status --porcelain` - -# chdir to the directory of the script -cd "$(dirname "${BASH_SOURCE[0]}") - -if [ ${#gstatus} -ne 0 ] -then - git add --all - git commit -m "Auto update: $gstatus" - git pull --rebase - git push -fi -``` +Run `:PlugInstall` diff --git a/plugin/vimwiki-sync.vim b/plugin/vimwiki-sync.vim index 07ab332..e01e934 100644 --- a/plugin/vimwiki-sync.vim +++ b/plugin/vimwiki-sync.vim @@ -1,6 +1,6 @@ " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 " Vimwiki-Sync plugin file -" Home: https://github.com/hv15/vimwiki-sync/ +" Home: https://github.com/icalvin102/vimwiki-sync/ function! s:vimwiki_get_paths_and_extensions() " Getting all extensions and paths that different wikis could have @@ -24,6 +24,38 @@ function! s:vimwiki_get_paths_and_extensions() return wikis endfunction +function! s:on_out(job_id, data, event) + echom 'VimWikiSync:' join(a:data, ' ') +endfunction + +function! s:on_exit(job_id, data, event) + echom 'VimWikiSync:' (a:data == 0 ? 'Finished syncing' : 'Syncing error') +endfunction + +function! CloseHandler(channel) + echom 'something something' + while ch_status(a:channel, {'part':'out'}) == 'buffered' + echom ch_read(a:channel) + endwhile +endfunction + +function! ExitHandler(channel,msg ) + echom "VimWikiSync: Finished" +endfunction + +function! s:vimwiki_sync(path) + let l:cmd = 'git -C "'. a:path .'" add --all && ' + let l:cmd .= 'git -C "'. a:path .'" commit -m "Auto update: $(git -C "'. a:path .'" status --porcelain)" ; ' + let l:cmd .= 'git -C "'. a:path .'" pull --rebase && ' + let l:cmd .= 'git -C "'. a:path .'" push' + if has('nvim') + let s:job = jobstart(l:cmd, {'on_stdout': function('s:on_out'),'on_stderr': function('s:on_out'), 'on_exit': function('s:on_exit') }) + else + let s:job = job_start(['/bin/sh', '-c', l:cmd], {'exit_cb': 'ExitHandler', 'close_cb': 'CloseHandler'}) + endif +endfunction + + let s:known_wiki_exts_paths = s:vimwiki_get_paths_and_extensions() augroup vimwiki @@ -31,7 +63,7 @@ augroup vimwiki for s:ext in keys(s:known_wiki_exts_paths) for s:path in s:known_wiki_exts_paths[s:ext] " sync changes at the start - exe 'autocmd BufRead,BufWritePost '.s:path.'*'.s:ext.' :Dispatch! "'.s:path.'/sync.sh"' + exe 'autocmd BufRead,BufWritePost '.s:path.'*'.s:ext.' :call s:vimwiki_sync("'.s:path.'")' endfor endfor augroup END