Skip to content

Instantly share code, notes, and snippets.

@chitoku-k
Last active October 25, 2020 14:50
Show Gist options
  • Save chitoku-k/8256d4b73ee8eafc41ddd985445ccd7d to your computer and use it in GitHub Desktop.
Save chitoku-k/8256d4b73ee8eafc41ddd985445ccd7d to your computer and use it in GitHub Desktop.
restart.bash

使い方

ファイルが更新されたときに実行したいコマンドをあとに続ける

./restart.bash php server.php
#!/usr/bin/env bash
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
args=("$@")
run() {
${args[@]} &
pid=$!
}
run
fswatch --exclude="$0" --one-per-batch --latency=2 --event=Updated . | while read line; do
if [[ -n $pid ]]; then
kill $pid
fi
run
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment