Skip to content

Instantly share code, notes, and snippets.

@Dubhead
Created March 5, 2013 04:43
Show Gist options
  • Save Dubhead/5088076 to your computer and use it in GitHub Desktop.
Save Dubhead/5088076 to your computer and use it in GitHub Desktop.
#!/bin/zsh -x
# ファイルに変更があったらブラウザを自動リロードする。
# ブラウザ側に拡張などを入れる必要なし。
# 要: inotifywait, xdotool
# 参考: http://stackoverflow.com/questions/4680109/how-to-reload-refresh-a-web-page-without-leaving-my-web-development-ide/10739606#10739606
# 参考: http://unix.stackexchange.com/questions/37258/refresh-reload-active-browser-tab-from-command-line/42933#42933
RELOAD_KEYS="CTRL+R"
# RELOAD_KEYS="SHIFT+CTRL+R"
DEFAULT_BROWSER="Mozilla Firefox"
BROWSER=$1
if [ -z "${BROWSER}" ]; then
BROWSER=$DEFAULT_BROWSER
fi
while true; do
inotifywait -qq --recursive --event modify ./
MYWINDOW=$(xdotool getactivewindow)
xdotool search --name ${BROWSER} windowactivate --sync
xdotool search --name ${BROWSER} key --clearmodifiers ${RELOAD_KEYS}
xdotool windowfocus --sync ${MYWINDOW}
xdotool windowactivate --sync ${MYWINDOW}
done
# eof vim:set syntax=zsh:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment