Skip to content

Instantly share code, notes, and snippets.

@letsspeak
Created July 30, 2012 00:35
Show Gist options
  • Save letsspeak/3202943 to your computer and use it in GitHub Desktop.
Save letsspeak/3202943 to your computer and use it in GitHub Desktop.
immediately rsync when the file in specific directory was written by vim (final edition)
#!/bin/sh
rsync -av -e "ssh -p XXXX" $1 [email protected]:$2
autocmd! BufWritePost * call SyncCharag()
function! SyncCharag()
let local_directory = "/Users/eveningsun/rails/charag/"
let remote_directory = "/home/www/rails/charag/"
let local_fullpath = getcwd()."/".bufname("%")
if local_fullpath =~ "^".local_directory
let local_directory_len = strlen(local_directory)
let local_tofile_len = strlen(local_fullpath) - local_directory_len
let local_tofile = strpart(local_fullpath, local_directory_len, local_tofile_len)
let remote_fullpath = remote_directory.local_tofile
exec 'call system("$HOME/bin/sync-charag ".local_fullpath." ".remote_fullpath)'
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment