Last active
March 2, 2021 14:08
-
-
Save ilyar/73184f11e706e83c8d2d4ce95e2d426b to your computer and use it in GitHub Desktop.
Compiling and running in Haskell this invention of the bicycle there is already a runhaskell for this
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
| #!/usr/bin/env bash | |
| # Usage: | |
| # ghc-run [ghc command-line-options-and-input-files] [-- programm-args] | |
| # Sample: | |
| # ghc-run main.hs | |
| # ghc-run main.hs -- foo bar | |
| # echo "foo bar" | ghc-run main.hs | |
| set -o errexit | |
| tmp=$(mktemp -d -t ci-XXXXXXXXXX) | |
| file="${1%.*}" | |
| delimiter="--" | |
| args=() | |
| params="${*}${delimiter}" | |
| while [[ ${params} ]]; do | |
| args+=( "${params%%"${delimiter}"*}" ) | |
| params=${params#*"${delimiter}"} | |
| done | |
| ghcArgs="-o ${tmp}/${file}" | |
| ghcArgs+=" -hidir ${tmp}" | |
| ghcArgs+=" -tmpdir ${tmp}" | |
| ghcArgs+=" -odir ${tmp}" | |
| ghcCMD="ghc ${ghcArgs} ${args[0]}" | |
| runCMD="${tmp}/${file} ${args[1]}" | |
| ${ghcCMD} | |
| ${runCMD} | |
| rm -rf "${tmp}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment