Up until recently, I was executing this beauty to build + run a project with stack:
stack build && .stack-work/install/x86_64-linux/lts-4.1/7.10.3/bin/<project-name>
I was told on IRC that this can be simplified to
stack build && stack exec <project-name>
Can this be simplified even more, to
stack run
or at least
stack run <project-name>
?
If I recall correctly this was possible with cabal run
.
Edit:
@haoformayor's comment is getting close:
alias b='stack build --fast --ghc-options="-Wall" && stack exec'
Although this still needs the project name, right?
I've also started to get close with
function stack-run () { stack build && stack exec `basename "$PWD"` }
Although this only works if the project name matches with the folder name. Maybe we can query cabal/stack for the first executable
entry in the .cabal file? Or Maybe we could do it with sed
...
I've had quite a good experience using:
https://hackage.haskell.org/package/stack-run
Edit 2018-04-05: Relevant stack issue.
Old answer:
This is what I ended up doing for now.
#/usr/bin/env sh
stack build && stack exec `basename "$PWD"` "$@"
I've put the following into a file named stack-run
under my $PATH
. ~/.local/bin/stack-run
in my case.
Which allows me to
$ stack-run
in any directory, and even
$ stack run
Since in almost all of my projects the executable of the project bears the same name as the folder, this works. But I hope to extend it with support for differing names as well.
Edit 2016-09-26: I've also found this, but haven't given it a try yet: https://hackage.haskell.org/package/stack-run