Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
36 changes: 34 additions & 2 deletions plugin/vimwiki-sync.vim
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,14 +24,46 @@ 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
autocmd!
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