Get the source directory of a Haskell Stack & Turtle script from within the script itself

64 views Asked by At

I've created a stack interpreted script using Turtle and I want to be able to get the directory where the script is (regardless of where it's been called from).

This can be done in Bash by parsing $0 or $BASH_SOURCE[0] (as described here, however, I can't work out how to do it with Stack/Turtle?

I've tried the FindBin library but it didn't work (it just returned the current working directory).

My script is currently defined like so:

#!/usr/bin/env stack
{- stack --resolver lts-13.3 script
    --package turtle
    --package text
-}

Is this possible with a stack script?

1

There are 1 answers

1
Michael Snoyman On

I think you can use the executable-path package to get this information:

https://www.stackage.org/haddock/nightly-2019-07-07/executable-path-0.0.3.1/System-Environment-Executable.html