2.3 KiB
2.3 KiB
Directory Sync Utility
This directory contains a tool for syncing a local directory to a remote host in real time. It watches for file changes and transfers them immediately via SCP, making it useful for live development on a remote server.
Scripts
| Script | Description |
|---|---|
dir-sync.sh |
Improved version — recommended |
scpsync.sh |
Original version |
Quick Start
./dir-sync.sh -s /path/to/local/dir/ -d /path/to/remote/dir/ -r sshhost
The script starts watching the local directory immediately. Press Ctrl+C to stop —
it will reset the remote repository (git reset --hard) and clear the remote cache before exiting.
Options
| Option | Description |
|---|---|
-s, --source <path> |
Local directory absolute path |
-d, --dest <path> |
Remote directory absolute path |
-r, --remote-host <h> |
Remote SSH host (as configured in ~/.ssh/config) |
-h, --help |
Print help |
If an option is omitted, the script falls back to the default values defined at the top of the script.
How It Works
- File watching:
fswatchmonitors the source directory for any change, excluding.git/ - Batch end marker:
fswatch --batch-markeremits aNoOpsignal at the end of each batch - File sync: each changed file is transferred with
scp, preserving the relative path under the destination directory - Cache clear: on each
NoOp(end of batch),composer front-cache-clearis run on the remote - Cleanup on exit: Ctrl+C triggers
git reset --hardand a final cache clear on the remote
Default Configuration
Edit the three constants at the top of dir-sync.sh to set your own defaults:
DEFAULT_LOCAL_PATH='/path/to/local/dir/'
DEFAULT_REMOTE_PATH='/path/to/remote/dir/'
DEFAULT_HOST='devac'
Requirements
fswatch— file system watcherscpandssh— standard OpenSSH tools- A remote host configured in
~/.ssh/config(password-less key auth recommended) composeravailable on the remote host (for cache clearing)
Installing fswatch
# macOS
brew install fswatch
# Linux (Ubuntu/Debian)
sudo apt install fswatch
About
Author: Julien Gautier (jgautier.webdev@gmail.com)
Organization: AdAstra
Project: adastra_scripts