Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix readme typo: ARsyncUP --> ARsyncUp #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Optional fields are:
- rsync will receive the flags `-varze` for remote syncing and `-var` for local syncing by default. Any flags you set using `rsync_flags` will override these flags.

## Usage
If ```auto_sync_up``` is set to 1, the plugin will automatically launch the ```:ARsyncUP``` command
If ```auto_sync_up``` is set to 1, the plugin will automatically launch the ```:ARsyncUp``` command
everytime a buffer is saved.

Setting ```rsync_flags``` to include `-ul`, for example, will use rsync's 'update' feature and will also copy over symlinks. Check out rsync's man page to see all the options it supports.
Expand Down
67 changes: 54 additions & 13 deletions plugin/vim-arsync.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,59 @@ function! LoadConf()
let l:conf_dict['local_options'] = "-var"
endif
if !has_key(l:conf_dict, "remote_options")
let l:conf_dict['remote_options'] = "-vazre"
let l:conf_dict['remote_options'] = "-vazr"
endif
return l:conf_dict
endfunction

function! JobHandler(job_id, data, event_type)
" redraw | echom a:job_id . ' ' . a:event_type
if a:event_type == 'stdout' || a:event_type == 'stderr'
" redraw | echom string(a:data)
if has_key(getqflist({'id' : g:qfid}), 'id')
call setqflist([], 'a', {'id' : g:qfid, 'lines' : a:data})
endif
elseif a:event_type == 'exit'
if a:event_type == 'exit'
if a:data != 0
copen
endif
if a:data == 0
elseif a:data == 0
let s:filename = expand('%:t')
echohl Green
echo "vim-arsync success."
echohl None
" Clear message after 2 seconds and show filename
call timer_start(2000, 'ShowFilename')
endif
" echom string(a:data)
endif
endfunction

function! ShowFilename(timer_id)
echo s:filename . " (project synced.)"
endfunction

" function! JobHandler(job_id, data, event_type)
" " redraw | echom a:job_id . ' ' . a:event_type
" let prev_msg = execute('messages')[-1]
" if a:event_type == 'stdout' || a:event_type == 'stderr'
" " redraw | echom string(a:data)
" if has_key(getqflist({'id' : g:qfid}), 'id')
" call setqflist([], 'a', {'id' : g:qfid, 'lines' : a:data})
" endif
" elseif a:event_type == 'exit'
" if a:data != 0
" copen
" endif
" if a:data == 0
" echo "vim-arsync success."
" call timer_start(2000, {-> execute('echo "'. prev_msg . '"')})
" endif
" " echom string(a:data)
" endif
" endfunction

function! ShowConf()
let l:conf_dict = LoadConf()
echo l:conf_dict
echom string(getqflist())
endfunction

function! ARsync(direction)
if filereadable('.vim-arsync-disabled')
return
endif
let l:conf_dict = LoadConf()
if has_key(l:conf_dict, 'remote_host')
let l:user_passwd = ''
Expand All @@ -84,7 +107,7 @@ function! ARsync(direction)
if a:direction == 'down'
let l:cmd = [ 'rsync', l:conf_dict['remote_options'], 'ssh -p '.l:conf_dict['remote_port'], l:user_passwd . l:conf_dict['remote_host'] . ':' . l:conf_dict['remote_path'] . '/', l:conf_dict['local_path'] . '/']
elseif a:direction == 'up'
let l:cmd = [ 'rsync', l:conf_dict['remote_options'], 'ssh -p '.l:conf_dict['remote_port'], l:conf_dict['local_path'] . '/', l:user_passwd . l:conf_dict['remote_host'] . ':' . l:conf_dict['remote_path'] . '/']
let l:cmd = [ 'rsync', l:conf_dict['remote_options'], "--filter", ':- .gitignore', l:conf_dict['local_path'] . '/', l:user_passwd . l:conf_dict['remote_host'] . ':' . l:conf_dict['remote_path'] . '/']
else " updelete
let l:cmd = [ 'rsync', l:conf_dict['remote_options'], 'ssh -p '.l:conf_dict['remote_port'], l:conf_dict['local_path'] . '/', l:user_passwd . l:conf_dict['remote_host'] . ':' . l:conf_dict['remote_path'] . '/', '--delete']
endif
Expand Down Expand Up @@ -127,6 +150,9 @@ function! ARsync(direction)
endfunction

function! AutoSync()
if filereadable('.vim-arsync-disabled')
return
endif
let l:conf_dict = LoadConf()
if has_key(l:conf_dict, 'auto_sync_up')
if l:conf_dict['auto_sync_up'] == 1
Expand All @@ -146,10 +172,25 @@ if !executable('rsync')
finish
endif

function! ARsyncToggle()
let l:filename = getcwd() . '/.vim-arsync-disabled'

if filereadable(l:filename)
call delete(l:filename)
echo "Enabled vim-arysnc auto sync up"
else
" File not found, create it
call writefile([], l:filename)
echo "Disabled vim-arysnc auto sync up"
endif
endfunction


command! ARsyncUp call ARsync('up')
command! ARsyncUpDelete call ARsync('upDelete')
command! ARsyncDown call ARsync('down')
command! ARshowConf call ShowConf()
command! ARsyncToggle call ARsyncToggle()

augroup vimarsync
autocmd!
Expand Down