Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iWoz/file_sync
Detect file modification in background and push it to git automatically.
https://github.com/iWoz/file_sync
Last synced: 8 days ago
JSON representation
Detect file modification in background and push it to git automatically.
- Host: GitHub
- URL: https://github.com/iWoz/file_sync
- Owner: iWoz
- License: mit
- Created: 2016-07-22T02:29:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T12:35:26.000Z (almost 2 years ago)
- Last Synced: 2024-08-13T07:09:42.539Z (4 months ago)
- Language: Python
- Size: 304 KB
- Stars: 140
- Watchers: 11
- Forks: 30
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - iWoz/file_sync - Detect file modification in background and push it to git automatically. (Python)
README
# file_sync
Synchronize your files to a git repository automatically.
When you have modified your files, files will be pushed to a remote git repository.
With git, you can know every change with your files by commits.
## Setup
* Install [git](https://git-scm.com/downloads)
* Install [Python](https://www.python.org/downloads/)* Install [watchdog](http://pythonhosted.org/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](imgs/new_git.png)
I made a new git repository named `configs` in [Github](https://github.com/new).
### Setup your git repository locally```bash
cd ~/Documents ## REPLACE ~/Documents TO WHATEVER DIR YOU LIKEmkdir configs
cd configsgit 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 you pushed successfully before you start the 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 :
```planitext
/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 mentioned in file_list.txt.
For example, I modified .zshrc, and then logs are:
![logs](imgs/logs.png)
And when I check the remote git repository, all worked ok:
![check](imgs/check.png)
### 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`
* WindowsI rarely use Windows, there is an ugly way to do this:
* make a bat file named `file_sync.bat`
* write `pythonw __YOUR_DIR__\file_sync.py` in this bat
* put this bat to your startup folder `C:\Documents and Settings\All Users\Start Menu\Programs\Startup`
* close the console because we use `pythonw`
* more infomation can be found in [here](http://stackoverflow.com/questions/4438020/how-to-start-a-python-file-while-window-starts)
* *nixI'm pretty sure you can make it happen by yourself when you use *nix :)
![image](https://user-images.githubusercontent.com/1621110/215088294-fc24b001-23d3-40e4-be2e-1f50a0d6d936.png)