Last active
August 29, 2015 14:07
-
-
Save maerten/2c9152f68e2bbefa93ac to your computer and use it in GitHub Desktop.
bash script to run yesod-dev's auto reload inside ghci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# bash script to run yesod-dev's auto reload inside ghci (faster template reloading) | |
# | |
# see also https://github.com/yesodweb/yesod/issues/754 | |
# | |
# needs tmux and fswatch, tested on MacOS 10.10 | |
# | |
function showHelp() { | |
echo "Usage: $0 -w" | |
echo "" | |
echo "(You need tmux and fswatch)" | |
} | |
function startGhciYesodDev() { | |
# start tmux with two windows: | |
# - ghci | |
# - fswatch (to trigger recompile on template change) | |
tmux start-server | |
tmux new-session -d -s ghci_server -n ghci | |
tmux split-window -t ghci | |
# start yesod with ghci | |
tmux select-pane -t 0 | |
tmux send-keys -t ghci_server:ghci "ghci -XViewPatterns" C-m | |
tmux send-keys -t ghci_server:ghci ":load Application" C-m | |
tmux send-keys -t ghci_server:0 "import Network.Wai.Handler.Warp" C-m | |
tmux send-keys -t ghci_server:0 "getApplicationDev >>= \(port, app) -> runSettings (setPort port defaultSettings) app" C-m | |
# watch templates with 'fswatch' | |
tmux select-pane -t 1 | |
tmux send-keys -t ghci:0 "fswatch -o ./templates | xargs -n1 $0" C-m | |
tmux select-window -t ghci_server:ghci | |
tmux attach-session -t ghci_server | |
} | |
function reloadTemplates() { | |
# send reload&restart commands to ghci | |
echo "$1 files changed, reloading..." | |
tmux select-window -t ghci_server:ghci | |
tmux select-pane -t 0 | |
tmux send-keys -t ghci_server C-c | |
tmux send-keys -t ghci_server ":load Application" C-m | |
tmux send-keys -t ghci_server "getApplicationDev >>= \(port, app) -> runSettings (setPort port defaultSettings) app" C-m | |
} | |
if [ "$1" == "" ]; then | |
showHelp | |
elif [ "$1" = "-w" ]; then | |
startGhciYesodDev | |
else | |
reloadTemplates $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment