Skip to content

Instantly share code, notes, and snippets.

@CNDW
Created October 2, 2019 13:52
Show Gist options
  • Save CNDW/b12f896d65335909ddfc4239d71e9920 to your computer and use it in GitHub Desktop.
Save CNDW/b12f896d65335909ddfc4239d71e9920 to your computer and use it in GitHub Desktop.
#!/bin/bash
FILENAME="pytest.html"
FILEPATH="$PWD/$FILENAME"
CMD="${@:1} --html=$FILENAME"
PROJECT_NAME=$(basename $PWD)
function runCommand {
$CMD
}
function openTab {
osascript <<EOF
tell application "Google Chrome"
activate
open location "file://$FILEPATH"
end tell
EOF
}
function refreshTab {
osascript <<EOF
tell application "Google Chrome"
activate
set windowList to every window
repeat with aWindow in windowList
set tabList to every tab of aWindow
repeat with atab in tabList
if (URL of atab contains "$FILEPATH") then
tell atab
activate
reload
end tell
end if
end repeat
end repeat
end tell
EOF
}
runCommand
openTab
fswatch -o $PWD/$PROJECT_NAME $PWD/test $PWD/lib -e ".*" -i "\\.py$" | while read file event; do
if [ "$file" == "2" ]; then
echo "change detected, running '$CMD'"
runCommand
refreshTab
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment