All Projects → psibi → Shell Conduit

psibi / Shell Conduit

Licence: bsd-3-clause
Write shell scripts with Conduit

Programming Languages

shell
77523 projects
haskell
3896 projects
scripting
82 projects

Labels

Projects that are alternatives of or similar to Shell Conduit

Fast Dat Parser
Superfast blockchain parser for stats
Stars: ✭ 68 (-24.44%)
Mutual labels:  stream
Stream
流媒体解锁后端
Stars: ✭ 71 (-21.11%)
Mutual labels:  stream
Iostreams
IOStreams is an incredibly powerful streaming library that makes changes to file formats, compression, encryption, or storage mechanism transparent to the application.
Stars: ✭ 84 (-6.67%)
Mutual labels:  stream
Target Postgres
A Singer.io Target for Postgres
Stars: ✭ 70 (-22.22%)
Mutual labels:  stream
Sec Api
sec.gov EDGAR API | search & filter SEC filings | over 150 form types supported | 10-Q, 10-K, 8, 4, 13, S-11, ... | insider trading
Stars: ✭ 71 (-21.11%)
Mutual labels:  stream
Node Promisepipe
Safely pipe node.js streams while capturing all errors to a single promise
Stars: ✭ 79 (-12.22%)
Mutual labels:  stream
Activity
⚡️ Activity app for Nextcloud
Stars: ✭ 67 (-25.56%)
Mutual labels:  stream
Pinbox
PinBox is a homebrew for 3DS system to stream content from a windows PC to 3DS.
Stars: ✭ 88 (-2.22%)
Mutual labels:  stream
Athenax
SQL-based streaming analytics platform at scale
Stars: ✭ 1,178 (+1208.89%)
Mutual labels:  stream
Cloud Media Scripts
Upload and stream media from the cloud with or without encryption. Cache all new and recently streamed media locally to access quickly and reduce API calls
Stars: ✭ 84 (-6.67%)
Mutual labels:  stream
Rxjavajdk8interop
RxJava 2/3 interop library for supporting Java 8 features such as Optional, Stream and CompletableFuture [discontinued]
Stars: ✭ 70 (-22.22%)
Mutual labels:  stream
Iter
Simple iterator abstract datatype, intended to iterate efficiently on collections while performing some transformations.
Stars: ✭ 71 (-21.11%)
Mutual labels:  stream
Opus Stream Decoder
Instantly decode Ogg Opus audio streams in chunks with JavaScript & WebAssembly (Wasm)
Stars: ✭ 80 (-11.11%)
Mutual labels:  stream
Write
Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
Stars: ✭ 68 (-24.44%)
Mutual labels:  stream
Advanced Php
最近打算写一些php一些偏微妙的教程,比如关于多进程、socket等相关,都是自己的一些感悟心得
Stars: ✭ 1,271 (+1312.22%)
Mutual labels:  stream
Freeiptv
FreeIPTV • Watch Free IPTV World Wide
Stars: ✭ 68 (-24.44%)
Mutual labels:  stream
String To Stream
Convert a string into a stream (streams2)
Stars: ✭ 75 (-16.67%)
Mutual labels:  stream
Backoffice Administration
Stars: ✭ 89 (-1.11%)
Mutual labels:  stream
Phpstreams
A streams library for PHP inspired by the Java 8 Streams API.
Stars: ✭ 87 (-3.33%)
Mutual labels:  stream
Optbinning
Optimal binning: monotonic binning with constraints. Support batch & stream optimal binning
Stars: ✭ 79 (-12.22%)
Mutual labels:  stream

shell-conduit Hackage Build Status

Write shell scripts with Conduit. Still in the experimental phase.

Haddock API documentation.

Examples

Cloning and initializing a repo
import Control.Monad.IO.Class
import Data.Conduit.Shell
import System.Directory

main =
  run (do exists <- liftIO (doesDirectoryExist "fpco")
          if exists
             then rm "fpco/.hsenvs" "-rf"
             else git "clone" "[email protected]:fpco/fpco.git"
          liftIO (setCurrentDirectory "fpco")
          shell "./dev-scripts/update-repo.sh"
          shell "./dev-scripts/build-all.sh"
          alertDone)
Piping

Piping of processes and normal conduits is possible:

λ> run (ls $| grep ".*" $| shell "cat" $| conduit (CL.map (S8.map toUpper)))
DIST
EXAMPLES
LICENSE
README.MD
SETUP.HS
SHELL-CONDUIT.CABAL
SRC
TAGS
TODO.ORG
Running actions in sequence and piping

Results are outputted to stdout unless piped into other processes:

λ> run (do shell "echo sup"; shell "echo hi")
sup
hi
λ> run (do shell "echo sup" $| sed "s/u/a/"; shell "echo hi")
sap
hi
Streaming

Live streaming between pipes like in normal shell scripting is possible:

λ> run (do tail' "/tmp/example.txt" "-f" $| grep "--line-buffered" "Hello")
Hello, world!
Oh, hello!

(Remember that grep needs --line-buffered if it is to output things line-by-line).

Handling exit failures

Process errors can be ignored by using the Alternative instance.

import Control.Applicative
import Control.Monad.Fix
import Data.Conduit.Shell

main =
  run (do ls
          echo "Restarting server ... ?"
          killall name "-q" <|> return ()
          fix (\loop ->
                 do echo "Waiting for it to terminate ..."
                    sleep "1"
                    (ps "-C" name >> loop) <|> return ())
          shell "dist/build/ircbrowse/ircbrowse ircbrowse.conf")
  where name = "ircbrowse"
Running custom things

You can run processes directly:

λ> run (proc "ls" [])
dist	  LICENSE    Setup.hs		  src	TODO.org
examples  README.md  shell-conduit.cabal  TAGS

Or shell commands:

λ> run (shell "ls")
dist	  LICENSE    Setup.hs		  src	TODO.org
examples  README.md  shell-conduit.cabal  TAGS

Or conduits:

λ> run (cat $| conduit (awaitForever yield))
hello
hello
Interrupted.
Keyboard configuration
import Data.Conduit.Shell
main =
  run (do xmodmap ".xmodmap"
          xset "r" "rate" "150" "50")

How it works

All executable names in the PATH at compile-time are brought into scope as runnable process conduits e.g. ls or grep.

All processes are bound as variadic process calling functions, like this:

rmdir :: ProcessType r => r
ls :: ProcessType r => r

But ultimately the types end up being:

rmdir "foo" :: Segment r
ls :: Segment r
ls "." :: Segment r

Etc.

Run all shell scripts with

run :: Segment r -> IO r

The Segment type has a handy Alternative instance.

String types

If using OverloadedStrings so that you can use Text for arguments, then also enable ExtendedDefaultRules, otherwise you'll get ambiguous type errors.

{-# LANGUAGE ExtendedDefaultRules #-}

But this isn't necessary if you don't need to use Text yet. Strings literals will be interpreted as String. Though you can pass a value of type Text or any instance of CmdArg without needing conversions.

Other modules

You might want to import the regular Conduit modules qualified, too:

import qualified Data.Conduit.List as CL

Which contains handy functions for working on streams in a list-like way. See the rest of the handy modules for Conduit in conduit-extra.

Also of interest is csv-conduit, html-conduit, and http-conduit.

Finally, see the Conduit category on Hackage for other useful libraries: http://hackage.haskell.org/packages/#cat:Conduit

All of these general purpose Conduits can be used in shell scripting.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].