Skip to content

Instantly share code, notes, and snippets.

@AmirMuha
Created July 6, 2023 15:53
Show Gist options
  • Save AmirMuha/c314e16f3c7487a7d747e22565153c17 to your computer and use it in GitHub Desktop.
Save AmirMuha/c314e16f3c7487a7d747e22565153c17 to your computer and use it in GitHub Desktop.
shell script for watching python file/files for changes
#!/bin/zsh
# Define color variables
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
clear_console=true
output=""
error=""
while true; do
if [ "$clear_console" = true ]; then
clear
echo "${NC}$output"
echo "${RED}$error"
clear_console=false
fi
inotifywait -e close_write main.py &>/dev/null
output=$(python main.py 2>&1)
if [ $? -eq 0 ]; then
error=""
else
error="$output"
output=""
fi
clear_console=true
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment