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
1
vote
2 answers

Is there a turtle function or other Haskell abstraction for joining commands using .&&

I have the following piece of code: foldM (\exitCode args -> pure exitCode .&&. someCmdWith args) ExitSuccess argss Which uses turtle's (.&&.) operator. Is there a better abstraction I could use to apply .&&. to the results of applying someCmdWith…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
1
vote
2 answers

Haskell Turtle get out of Shell Monad

could you please help me with Turtle library. I want to write simple program, that calculates disk space usage. Here is the code: getFileSize :: FilePath -> IO Size getFileSize f = do status <- stat f return $ fileSize status main = sh $ do …
1
vote
1 answer

How can a `Shell Text` be converted to `Shell Line`?

In a Turtle script for getting passwords from a keyring, calling ssh-add with those passwords so they don't have to be filled out manually, is the following function: processKey :: (T.Text, T.Text) -> Shell Line -> IO () processKey (kn, str) pwds =…
user4301448
  • 191
  • 10
1
vote
1 answer

How can I capture stdout and stderr output from a process with Haskell turtle?

{-# LANGUAGE OverloadedStrings #-} import Turtle runSh :: Text -> IO () runSh x = view $ inshell x empty main :: IO () main = do runSh "echo 'abcxyz'" I've got the above program which outputs: Line "abcxyz" Is there a way I can capture this…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
1
vote
1 answer

Haskell Turtle Script: How to consume Shell

import Turtle import Prelude hiding (FilePath) import Data.Text hiding (find) main = do f <- view $ format fp <$> find (suffix ".mp4") "/Users/me/videos" procs "ffmpeg" ["-vn","-acodec","libmp3lame","-ac","2","-ab","160k","-ar","48000","-i"]…
McBear Holden
  • 5,741
  • 7
  • 33
  • 55
1
vote
1 answer

Preserving Bash Colors When Shelling out Commands in Haskell

Running ls --color=auto in bash shows directories as blue on my machine. Yet running stdout (inshell "ls --color=auto" empty) in Turtle loses all said color data. Is there a way to preserve coloring data?
George
  • 6,927
  • 4
  • 34
  • 67
1
vote
1 answer

Using Haskell's Turtle to Call a Custom Bash Function

Using turtle, how does one run a custom bash command found in /a/path/to/a/file.sh? It would be the equivalent of source /a/path/to/a/file.sh and then calling custom_bash_function.
George
  • 6,927
  • 4
  • 34
  • 67
1
vote
2 answers

With haskell's turtle library, how to extract filename as String from FilePath?

When using takeFileName I get a type error: :t v print v :t takeFileName takeFileName v v :: FilePath FilePath "/media/miguel/backup/backups" takeFileName :: FilePath -> FilePath Couldn't match type ‘Turtle.FilePath’ with ‘String’ Expected type:…
miguel.negrao
  • 949
  • 5
  • 13
0
votes
1 answer

In Haskell's Turtle libarary, how to copy a file, but preserve the file date

I copy a file with the Turtle library. I do so like this: ... do TU.cp oldname newname ... However this sets the date of the copied file to the current time - how can I keep the original date as a shell would do with cp -p?
halloleo
  • 9,216
  • 13
  • 64
  • 122
0
votes
1 answer

How do I (optionally) pipe text into a Turtle shell script?

I am working on a Turtle based shell script. I'd like it to be able to, optionally, accept piped in text in place of an argument. After reading the docs and playing with the stdin Turtle function to no avail, I realize I'm stuck. Is something like…
0
votes
2 answers

Haskell Turtle - getting Text output from inshellWithErr

What I tried: main :: IO () main = do let eitherSuccessOrErrorLine = inshellWithErr "stack build" empty stackBuildOutput <- strict $ case eitherSuccessOrErrorLine of Shell (Left line) -> line Shell (Right line) -> line putStr…
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
0
votes
1 answer

Haskell: Turtle: Managing Shell type

This a working snippet: import Turtle ... groom :: FilePath -> IO () groom src = do view (ls src) ... I can see a list of paths on the console. Actually I'd like to have something like [FilePath] for use, e.g.: treeCount :: FilePath ->…
Alexey Orlov
  • 2,412
  • 3
  • 27
  • 46
0
votes
1 answer

How to pass a password to scp with Turtle?

This is what I got: shell "scp -r /path_to_some_dir some_user@some_ip:destination_path" empty and, naturally, I get prompted for the password. Can the inputting of the password be automated with Turtle?
Lay González
  • 2,901
  • 21
  • 41
0
votes
2 answers

Using Haskell Turtle's FilePath with readFile

I am trying to use Haskell Turtle to do some CSV file processing, but I'm having trouble working with the Turtle.FilePath from the option parser. Here's an exampple: {-# LANGUAGE OverloadedStrings #-} module Main where import Lib import…
MattoxBeckman
  • 3,682
  • 2
  • 20
  • 16
0
votes
1 answer

How to print paths using Haskell Turtle library?

To learn a bit about Turtle, I thought it would be nice to modify example from the tutorial. I chose to remove the reduntant "FilePath" from each line of the output thinking it would be a simple exercise. And yet, despite author's efforts into…
sevo
  • 4,559
  • 1
  • 15
  • 31