#!/usr/bin/env bash # Configuration SERVER="${SERVER:-http://localhost:2025}" USERNAME="${API_USERNAME:-admin}" PASSWORD="${API_PASSWORD:-password}" # Check command line arguments if [ $# -lt 1 ]; then echo "Error: Watch directory not specified." echo "Usage: $0 " echo "Example: $0 /path/to/watch" exit 1 fi WATCH_DIR="$1" # Verify that the directory exists if [ ! -d "$WATCH_DIR" ]; then echo "Error: Directory '$WATCH_DIR' does not exist or is not a directory." exit 1 fi # Check if watchexec is installed if ! command -v watchexec &> /dev/null; then echo "Error: watchexec is not installed. Please install it first." echo "You can install it via cargo: cargo install watchexec-cli" echo "Or check https://github.com/watchexec/watchexec for other installation methods." exit 1 fi # Check if curl is installed if ! command -v curl &> /dev/null; then echo "Error: curl is not installed. Please install it first." exit 1 fi echo "Starting file watch in directory: $WATCH_DIR" echo "Server endpoint: $SERVER" echo "Using auth username: $USERNAME" echo "Use Ctrl+C to stop watching" # Run watchexec to monitor file changes # -w: Watch directory # -e: File extensions to monitor (adjust as needed) # --ignore: Ignore patterns (e.g., temporary files) watchexec -w "$WATCH_DIR" -e "*" --ignore "*.tmp,*.swp,*.~,*.log" \ "FILE={path}; echo 'File changed: $FILE'; if [ -f \"$FILE\" ]; then echo 'Uploading $FILE to $SERVER/upload/'; curl -v --user \"$USERNAME:$PASSWORD\" -F 'file=@$FILE' '$SERVER/upload/'; echo ''; fi"