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
2
votes
1 answer

How am I meant to use sort?

In Haskell Turtle, sort has the type (Functor io, MonadIO io, Ord a) => Shell a -> io [a]. It takes a stream in the form of a Shell monad, sorts it into a list, but then wraps it in a MonadIO??? This seems counter-intuitive to me. My beginner eyes…
mikevdg
  • 370
  • 1
  • 7
2
votes
1 answer

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

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…
tomphp
  • 307
  • 1
  • 4
  • 10
2
votes
1 answer

How can I make GHCI recognize working directory changes?

I am experimenting with using ghci+Turtle as my interactive shell instead of bash. So far it's working pretty well! But I'd really like Turtle's cd function to change ghci's working directory, the way ghci command :cd does. Let's say I load ghci…
Thomas Nelson
  • 693
  • 5
  • 17
2
votes
0 answers

How to run/compose multiple commands in a haskell turtle subshell

I'm trying to execute several commands in a subshell, e.g. (cd ~ && pwd) in bash. I can do home >>= cd in the current shell to combine some operations, but I can't figure out how I can do the same in a subshell. I went through the documentation and…
Carlos Morera
  • 377
  • 4
  • 12
2
votes
0 answers

Failing `Turtle` `Shell` without throwing an error

I have a program that is supossed to parse the output lines of a program, and produce some output data structure that contains some information extracted from those lines. For doing this I'm using turtle: import Turtle import qualified Control.Foldl…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
2
votes
0 answers

Run a command via ssh with Shelly/Turtle

Given a command: ssh user@host command where command, when executed on the remote host host, should be: somecmd --option1 'option value with spaces' 'arg1 with spaces' 'arg2 with weird chars, like (' How can I execute this command using the…
Incömplete
  • 853
  • 8
  • 20
2
votes
1 answer

In Turtle, how do I take stdout from a program, process it, and then supply something to stdin?

I am currently playing with format string attacks in C. I have a toy program that prints (to stdout) the address of a variable that I want to access, then accepts a line from stdin and printfs it.. Using Turtle, I'd like to be able to: execute the…
rossng
  • 318
  • 3
  • 11
2
votes
1 answer

Finding all the files under a directory in turtle that match a pattern

I'd like to use the find function from the turtle package such that it matches any file path (in order to get an equivalent behavior to find . in bash). However I cannot find a wildcard pattern that I can use with this function. find :: Pattern a ->…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
2
votes
2 answers

How to Convert a `Shell Line` to `Text` in Haskell Turtle Library?

Consider (inshell "echo A line of text." empty) has type Shell Line. Question: How can one convert a value of this type to Text?
George
  • 6,927
  • 4
  • 34
  • 67
2
votes
0 answers

Forking Turtle inshell command not streaming stdout

I'm using the the following function to fork commands in my Turtle script: forkCommand shellCommand = do pid <- inshell (shellCommand <> "& echo $!") empty return $ PID (lineToText pid) The reason for doing this is because I want to get the PID…
FintanH
  • 110
  • 11
2
votes
1 answer

Stack interpreter option - Add an external dependency

I'm making a script with Turtle and I need a dependency from GitHub. I saw that you can add such a dependency when you make a project by putting this in your stack.yaml: packages: - location: git: https://github.com/githubuser/reponame.git …
Elie Génard
  • 1,673
  • 3
  • 21
  • 34
2
votes
1 answer

what is the command to create a soft link with haskell turtle?

which command creates a softlink with the turtle package? there is a command to copy a file: the command cp (which is in Turtle.Prelude) but how to make a soft link, i.e. the equivalent of ln -s ? one could use used shell or any of the related…
user855443
  • 2,596
  • 3
  • 25
  • 37
1
vote
1 answer

Turtle in haskell: How to switch to a directory obtained from inshell command?

I am learning Haskell and I am having a hard time performing the following task. I have a script that gives me a directory. I would like to call that script, get the directory and then use the "cd" in Turtle to change the directory. Below is the…
user3716072
  • 187
  • 1
  • 2
  • 14
1
vote
0 answers

How to write a Haskell program that initiates and can then run commands in a nix-shell environment?

I would like to initiate a nix-shell (if unfamiliar with Nix), this can be thought of as a bashs hell that loads a particular environment, somewhat expensively). Once initiated as a separate process, I'd like to be able to send commands to that…
bbarker
  • 11,636
  • 9
  • 38
  • 62
1
vote
0 answers

How to switch current working directory while not resolving realpath in Haskell?

In my use case, I want to spawn a shell with current directory set to a specific one for users to perform some operations, the problem is user often have their PS1 set to print current working directory and I don't want a long ridiculous path to…
Javran
  • 3,394
  • 2
  • 23
  • 40