diff --git a/auto-update b/auto-update index 16d5aca..42611ed 100755 --- a/auto-update +++ b/auto-update @@ -25,6 +25,7 @@ relaunchCompilation() { done } +echo "First launch" | relaunchCompilation case $(uname) in Darwin) # On mac OS X, use hobbes (cabal install hobbes) diff --git a/scaffold/auto-update b/scaffold/auto-update index 88f37dc..42611ed 100755 --- a/scaffold/auto-update +++ b/scaffold/auto-update @@ -1,16 +1,51 @@ #!/usr/bin/env zsh +autoload colors +colors +for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do + eval $COLOR='$fg_no_bold[${(L)COLOR}]' + eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]' +done +eval RESET='$reset_color' + +latestThread=0 relaunchCompilation() { while read line; do if (( $( print -- $line | grep '.cabal-sandbox' | wc -l) == 0 )); then - print "$line" - cabal install - ./.cabal-sandbox/bin/test-{{projectName}} + (($latestThread>0)) && \ + (( $(ps x | awk "\$1 == $latestThread" | wc -l)>0 )) && { + print -- "\n${RED}STOPPED${RESET}" + kill $latestThread + } + print "${BLUE}$line${RESET}" + { cabal install && \ + ./.cabal-sandbox/bin/test-holy-project } & + latestThread=$! fi done } -# launch a cabal install and cabal test after each -# small haskell file modification -{hobbes "*.hs" | relaunchCompilation } & -hobbes "*.cabal" | relaunchCompilation +echo "First launch" | relaunchCompilation +case $(uname) in +Darwin) + # On mac OS X, use hobbes (cabal install hobbes) + # launch a cabal install and cabal test after each + # small haskell file modification + {hobbes "*.hs" | relaunchCompilation } & + hobbes "*.cabal" | relaunchCompilation + ;; +*) # On other Unixes + tmp=$(date +"%s") + t=$tmp + while true; do + tmp=$(( $t - 1 )) + t=$(date +"%s") + for fic in {src,test}/**/*.hs(.) *.cabal; do + # note to use on OS X, use "stat -f %m $checkfile" instead + modtime=$(stat --printf %Y $fic) + (( $modtime > $tmp )) && print $fic + done + sleep 1 + done | relaunchCompilation + ;; +esac diff --git a/src/HolyProject.hs b/src/HolyProject.hs index 1196b44..af42629 100644 --- a/src/HolyProject.hs +++ b/src/HolyProject.hs @@ -44,7 +44,7 @@ data Project = Project { , synopsis :: String , year :: String } deriving (Data, Typeable) --- | Randomly choose an end scenario and then show a "serious" error message +-- | Randomly choose an end scenario and then show a \"serious\" error message holyError :: String -> IO () holyError str = do r <- randomIO diff --git a/src/HolyProject/GithubAPI.hs b/src/HolyProject/GithubAPI.hs index b2f557d..962fef5 100644 --- a/src/HolyProject/GithubAPI.hs +++ b/src/HolyProject/GithubAPI.hs @@ -14,15 +14,14 @@ import qualified Data.Text.Lazy.Builder as TLB import Control.Monad ((<=<)) -- | make a simple http request but add a user agent to the HTTP header +-- You HAVE TO add a User-Agent in your header to use the github API. simpleHTTPWithUserAgent :: String -> IO LZ.ByteString simpleHTTPWithUserAgent url = do r <- parseUrl url let request = r { requestHeaders = [ ("User-Agent","HTTP-Conduit") ] } withManager $ (return.responseBody) <=< httpLbs request --- | Ask the github API --- A strange behaviour you HAVE TO add a User-Agent in your header. --- It took me way too long to get this error +-- | Search a username using the github API searchGHUser :: String -> IO (Maybe String) searchGHUser "" = return Nothing searchGHUser email = do diff --git a/src/HolyProject/MontyPython.hs b/src/HolyProject/MontyPython.hs index 518e7df..1bbce83 100644 --- a/src/HolyProject/MontyPython.hs +++ b/src/HolyProject/MontyPython.hs @@ -26,7 +26,7 @@ colorPutStr color str = do setSGR [] -- | Ask for some info and returns it -ask :: String -- ^ What? "name" for example +ask :: String -- ^ What? \"name\" for example -> Maybe String -- ^ Default value -> IO String ask info hint = do