Skip to content
/ file_sync Public

Detect file modification in background and push it to git automatically.

License

Notifications You must be signed in to change notification settings

iWoz/file_sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

file_sync

Synchronize your files to a git repository automatically.

When you modified your files, file will be pushed to a remote git repository.

With git, you can know every change with your file by commits.

##Setup

  • Install Python

  • Install watchdog

    in OS X or *nix:

     pip install watchdog
    

    in Windows:

     python -m pip install watchdog
    

##How to use ###Make a new git repository for synchronize your files

new git repository

I made a new git repository named sync_configs in Github.

###Setup your git repository locally

cd ~/Documents ## REPLACE ~/Documents TO WHATEVER DIR YOU LIKE

mkdir configs
cd configs

git init

## REPLACE [email protected]:iWoz/configs.git TO YOUR GIT REPOSITORY CREATED BEFORE
git remote add origin [email protected]:iWoz/configs.git 

## add submodule
git submodule add [email protected]:iWoz/file_sync.git

## stage all, commit and push to remote
git add -A
git commit -m "First commit."
git push -u origin master
## make sure pushed successfully to start next step

###Setup your file_list.txt for files to synchronize

Make a new file name file_list.txt in root of your git repository.

For example, contents in my file_list.txt are :

/Users/Tim/.zshrc
/Users/Tim/Library/Application Support/Sublime Text 2/Packages/User/Default (OSX).sublime-keymap
/Users/Tim/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings

Make sure one line one file in its absolute path.

###Test Run file_sync.py in submodule file_sync

cd file_sync
python file_sync.py

Now modify one of your files in file_list.txt.

For example, I modified .zshrc, and then logs are:

logs

And when I check the remote git repository, all is worked ok:

check

###Auto run when system startup

  • OS X
    • make a file named com.wuzhiwei.filesync.plist in ~/Library/LaunchAgents/

    • fill the plist with content below

Label com.wuzhiwei.filesync Program /Users/Tim/Documents/configs/file_sync/file_sync.py RunAtLoad KeepAlive UserName Tim StandardErrorPath /Users/Tim/Documents/configs/file_sync/file_sync_error.log StandardOutPath /Users/Tim/Documents/configs/file_sync/file_sync_output.log ``` * replace to your real path or username in lines below `REPLACE BELOW TO ...` * load the plist to system service: `launchctl load ~/Library/LaunchAgents/com.wuzhiwei.filesync.plist` * *if you want to unload the autorun service:* `launchctl unload ~/Library/LaunchAgents/com.wuzhiwei.filesync.plist` * check if the service is run in back: `launchctl list | grep com.wuzhiwei.filesync` * Windows
I rarely use Windows, there is an ugly way to do this:

* make a bat file named `file_sync.bat`
* write `python  UPPER_DIR\file_sync.py` in this bat
* put this bat to your startup folder `C:\Documents and Settings\All Users\Start Menu\Programs\Startup`
* more infomation can be found in [here](http://stackoverflow.com/questions/4438020/how-to-start-a-python-file-while-window-starts)
  • *nix

    I'm pretty sure you can make it happen by yourself when you use *nix :)

About

Detect file modification in background and push it to git automatically.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages