Questions tagged [haskell-turtle]

turtle is a reimplementation of the Unix command line environment in Haskell so that you can use Haskell as both a shell and a scripting language.

turtle is a reimplementation of the Unix command line environment in Haskell so that you can use Haskell as both a shell and a scripting language.

Features include:

  • Batteries included: Command an extended suite of predefined utilities

  • Interoperability: You can still run external shell commands

  • Portability: Works on Windows, OS X, and Linux

  • Exception safety: Safely acquire and release resources

  • Streaming: Transform or fold command output in constant space

  • Patterns: Use typed regular expressions that can parse structured values

  • Formatting: Type-safe printf-style text formatting

  • Modern: Supports text and system-filepath

Read Turtle.Tutorial for a detailed tutorial or Turtle.Prelude for a quick-start guide

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.

ref: https://hackage.haskell.org/package/turtle

49 questions
8
votes
1 answer

Is it possible to debug Turtle scripts (equivalent of "-x" flag in bash)?

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…
Jan Hrcek
  • 626
  • 11
  • 24
6
votes
3 answers

Composing ExitCodes in Turtle. Why is there no Monad/Monad Transformer instance?

I am writing a shell script in Haskell using turtle and would like to know best practices on composing commands that could fail. Now I have a case expression staircase, like so: runRemote :: MonadIO io => Text -> Text -> io () runRemote oldVersion'…
DJG
  • 6,413
  • 4
  • 30
  • 51
5
votes
2 answers

Haskell: Turtle: get a return value out of a Shell

How do you extract a value out of the Shell monad? I would like to sequence a list of commands à la bash's &&, but I would also like to extract the final ExitCode value. Say I have the following code: import Turtle type Commands = [Shell…
5
votes
2 answers

Launching Programs (example: Vim) from Haskell

Using the Turtle shell scripting library I am trying to launch a program, i.e: shell "vim" empty The problem is that this yields the warning Warning: Input is not from a terminal and causes Vim to lag for a few seconds before finally…
George
  • 6,927
  • 4
  • 34
  • 67
4
votes
1 answer

How to pipe stdout/stderr to the stdin of another command in Turtle?

The title pretty much says it all, I couldn't locate this answer obviously worded in the docs. I'm also unclear on how one would save-off stdout/stderr in a variable for later use to piping to stdin for multiple commands. Something conceptually…
josiah
  • 1,314
  • 1
  • 13
  • 33
4
votes
2 answers

Binary redirection in Turtle

I would like to do something similar to: curl -s http://example.com/some/file.bin >/usr/local/bin/foo Since Shell is polymorphic, I can probably do this with Turtle as-is, but all the examples operate on lines of Shell Text and I haven't…
drewr
  • 1,778
  • 1
  • 16
  • 20
3
votes
1 answer

Should I use folds in Turtle or Foldl packages?

I'm having some difficulty using Turtle and only after several minutes staring at incomprehensible error messages realized that I was using wrong fold…
sevo
  • 4,559
  • 1
  • 15
  • 31
3
votes
1 answer

Turtle: how to read a list of files?

Assume we have a file my_file.txt with contents: foo bar and another file my_other_file.txt containing: baz I would like to read the contents of these two files using turtle so that I get a Shell of lines which will produce: foo bar baz In…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
3
votes
2 answers

Running interactive commands with haskell turtle library

I am trying to run an interactive command with haskell turtle library like this: #!/usr/bin/env stack -- stack --install-ghc runghc --package turtle {-# LANGUAGE OverloadedStrings #-} import Turtle main = procs "python" [] empty (I also tried…
yilmazhuseyin
  • 6,442
  • 4
  • 34
  • 38
3
votes
1 answer

Convert String to Turtle.FilePath

How can I convert a concatenated String to a Turtle FilePath? For instance, the following program tries to read some text files, concatenate them into a new one and remove the old ones. It does not seem to work although the OverloadedStrings…
jarandaf
  • 4,297
  • 6
  • 38
  • 67
3
votes
2 answers

Haskell Turtle - split a shell

Is it possible to split a Shell in Turtle library (Haskell) and do different things to either split of the shell, such that the original Shell is only run once ? /---- shell2 ---Shell1 --/ \ \-----shell3 For…
miguel.negrao
  • 949
  • 5
  • 13
3
votes
1 answer

Haskell: Turtle: command line parser

I've been trying to build a command line parser with Turtle, nothing fancy: https://github.com/Tyrn/go-procr #!/usr/bin/env stack {-# LANGUAGE OverloadedStrings #-} module Main where import Turtle import Prelude hiding (FilePath) parserSwitch ::…
Alexey Orlov
  • 2,412
  • 3
  • 27
  • 46
3
votes
2 answers

Turtle: Prompting for input, without a trailing newline

I'm writing a console application that needs to prompt the user for several things. I'm using the turtle library. My function looks like this: askInput :: IO (Maybe Text) askInput = do echo "Input something: " s <- readline return s But…
Mariano
  • 1,357
  • 3
  • 17
  • 30
3
votes
4 answers

How to grep result of ls in Turtle

I'm playing with Turtle and I'm faced with the following problem. I want to do something like (in shell) ls | grep 'foo' My attempt using Turtle is grep (prefix "foo") (ls ".") & view But I got the following message Couldn't match type…
mb14
  • 22,276
  • 7
  • 60
  • 102
3
votes
1 answer

how to drop lines when streaming from a file using Haskell and the turtle library

Let's say I want to stream from one file to another file but I want to skip the first n lines of the input file. How do I do this without first collapsing the whole first file using 'fold' ? import Turtle main = output "/tmp/b.txt" (f (input…
miguel.negrao
  • 949
  • 5
  • 13
1
2 3 4