I've recently started using Haskell Turtle library to replace some of my shell scripts.
Is there a way to somehow enable echoing of built in Turtle commands (like cd) ala set -x
in bash scripts? I find it quite problematic to debug Turtle scripts in cases where many commands are executed and one of them fails with exception (like cp
command with Exception:openBinaryFile: does not exist
). Alternatively do you have some recommendation how to quickly isolate problems like these, so that I don't have to intersperse puStrLn/echo
commands throughout my script?
Bash provides extensive debugging features. The most common is to start up the subshell with the -x option, which will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed.
Invoking a Bash shell with the -x option causes each shell command to be printed before it is executed. This is especially useful for diagnosing problems with installation shell scripts. This option can only be used with Linux shell scripts, not with binary executables.
Open that in VS-code. First you will Cmd+Shift+P to go into command menu. Then you will type debug: Open launch. json, after this choose bash debug then select script from drop down (1st option).
Sadly, it is not possible, as turtle does not provide tracing. For example, mv
is defined only with Haskell function (no shell call), so there is no way to print anything when it is ran:
mv :: MonadIO io => FilePath -> FilePath -> io ()
mv oldPath newPath = liftIO (Filesystem.rename oldPath newPath)
This limitation mentioned in the documentation, where the author recommends to take a look at Shelly, which is similar but provide extra features:
turtle is designed to be beginner-friendly, but as a result lacks certain features, like tracing commands. If you feel comfortable using turtle then you should also check out the Shelly library which provides similar functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With