近期将办公电脑从windows换成了mac,以前一直用windows,在windows下面将代码同步到远程的开发机,zend studio有一些内置的工具,但mac下的zend stduio没有了这个工具。而sublime一些同步插件太难用,于是网上搜索,自己来实现同步。

1,在mac上面后台运行一个脚本,原理就是用mac的fswatch命令检测目录内文件的变化,然后通过rsync命令同步变化的文件到远程开发机,代码如下:

PWD="/Users/huangxuan01/Desktop/baidu/adu/eap-dp-platform/fe/"
cd $PWD
fswatch $PWD  | while read file
do
echo "======"
#只需要相对路径 sub_path=${file/${PWD}/} echo $sub_path

if [[ "$sub_path" == *\.git* ]];then


    echo ignore


    continue


fi


#去掉第一个斜线 sub_path
=${sub_path/\//} echo $sub_path if [ -f ${file} -o -d ${file} ] then rsync -aR ${sub_path} rsync://10.100.45.234:8667/www fi echo "======" done

2,在远程开发机上,运行rsync服务端。配置如下:

id = work  
port = 8667
address = 127.0.0.1
gid = work
use chroot = no
max connections = 10
strict modes = yes
log file = /home/work/rsync.log
pid file = /home/work/rsync.pid
[www]
path = /home/work/baidu/adu/eap-dp-platform/fe/
comment = analyse
read only = false
hosts allow = *