From ef19bd13829d0425188333a77acf1359d8537d78 Mon Sep 17 00:00:00 2001 From: Immanuel Calvin Herchenbach <40042006+icalvin102@users.noreply.github.com> Date: Mon, 17 Aug 2020 00:40:18 +0200 Subject: [PATCH 1/4] Added missing quotes in README.md / sync.sh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c02722..70af297 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ provides several improvements. These include: gstatus=`git status --porcelain` # chdir to the directory of the script -cd "$(dirname "${BASH_SOURCE[0]}") +cd "$(dirname "${BASH_SOURCE[0]}")" if [ ${#gstatus} -ne 0 ] then From ec70d06f5d6aa59a183ade7d5cb32878670dede2 Mon Sep 17 00:00:00 2001 From: icalvin102 Date: Mon, 17 Aug 2020 12:01:57 +0200 Subject: [PATCH 2/4] added jobstart support for neovim removed vim-dispatch dependency --- README.md | 31 ++++--------------------------- plugin/vimwiki-sync.vim | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 70af297..0bc7e63 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,8 @@ 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` - -```bash -#!/bin/bash - -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 -``` +At the moment this fork is working in *NeoVim Only* as it uses the `jobstart` +function of NeoVim. diff --git a/plugin/vimwiki-sync.vim b/plugin/vimwiki-sync.vim index 07ab332..90ae226 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,23 @@ 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! 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' + let job = jobstart(l:cmd, {'on_stdout': function('s:on_out'),'on_stderr': function('s:on_out'), 'on_exit': function('s:on_exit'), }) +endfunction + + let s:known_wiki_exts_paths = s:vimwiki_get_paths_and_extensions() augroup vimwiki @@ -31,7 +48,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 From 82c007e39b92e8f85c0f609241a8ac74cbb47e71 Mon Sep 17 00:00:00 2001 From: icalvin102 Date: Mon, 17 Aug 2020 13:20:16 +0200 Subject: [PATCH 3/4] added job_start to support vim --- plugin/vimwiki-sync.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugin/vimwiki-sync.vim b/plugin/vimwiki-sync.vim index 90ae226..e01e934 100644 --- a/plugin/vimwiki-sync.vim +++ b/plugin/vimwiki-sync.vim @@ -32,12 +32,27 @@ 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' - let job = jobstart(l:cmd, {'on_stdout': function('s:on_out'),'on_stderr': function('s:on_out'), 'on_exit': function('s:on_exit'), }) + 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 From 75b5747763b483d2131ab9be708a9066974be829 Mon Sep 17 00:00:00 2001 From: icalvin102 Date: Mon, 17 Aug 2020 13:31:41 +0200 Subject: [PATCH 4/4] added Install section to README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0bc7e63..3551606 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,8 @@ vimwiki-sync This is a fork of [vimwiki-sync](https://github.com/jerryyin/vimwiki-sync) without external dependencies. -At the moment this fork is working in *NeoVim Only* as it uses the `jobstart` -function of NeoVim. +## Install + +Add `Plug 'icalvin102/vimwiki-sync'` to your .vimrc + +Run `:PlugInstall`