package feather

  1. Overview
  2. Docs

Module FeatherSource

Creating and combining Feather commands

Sourcetype cmd

process constructs a new cmd that can be run with run or collect

Sourceval (|.) : cmd -> cmd -> cmd

|. is Feather's version of a "|" in bash; pipe the first process's stdout to the next's stdin.

Sourceval and_ : cmd -> cmd -> cmd

and_ is feather's version of a "&&" in bash. See Infix module for more.

Sourceval or_ : cmd -> cmd -> cmd

or_ is feather's version of a "||" in bash. See Infix module for more.

Sourceval sequence : cmd -> cmd -> cmd

sequence is feather's version of a ";" in bash. See Infix module for more.

Running Feather commands

Run a command without collecting anything

Sourcetype 'a what_to_collect

The type that determines what should be returned by collect

Various collection possibilities, to be used with collect

Sourceval stdout_and_stderr : (Base.string * Base.string) what_to_collect
Sourceval stdout_and_status : (Base.string * Base.int) what_to_collect
Sourceval stderr_and_status : (Base.string * Base.int) what_to_collect
Sourcetype everything = {
  1. stdout : Base.string;
  2. stderr : Base.string;
  3. status : Base.int;
}
Sourceval collect : ?cwd:Base.string -> ?env:(Base.string * Base.string) Base.list -> 'a what_to_collect -> cmd -> 'a

collect col cmd runs cmd, collecting the outputs specified by col along the way and returning them. The return type depends on what is collected.

Sourcetype 'a background_process
Sourceval run_in_background : ?cwd:Base.string -> ?env:(Base.string * Base.string) Base.list -> cmd -> Base.unit background_process
Sourceval collect_in_background : ?cwd:Base.string -> ?env:(Base.string * Base.string) Base.list -> 'a what_to_collect -> cmd -> 'a background_process

collect_in_background and run_in_background run the command in a thread.

Use wait to wait for the process to finish (and retreive whatever you collected).

Sourceval wait : 'a background_process -> 'a

wait for the result of run_in_background or collect_in_background.

Sourceval wait_all : Base.unit -> Base.unit

Wait for all processes started in the background.

Commands to insert OCaml within a Feather pipeline

Sourceval map_lines : f:(Base.string -> Base.string) -> cmd

map_lines within a sequence of pipes will be run with a thread. Same goes for filter_lines, mapi_lines, etc.

Sourceval filter_lines : f:(Base.string -> Base.bool) -> cmd
Sourceval mapi_lines : f:(Base.string -> Base.int -> Base.string) -> cmd
Sourceval filteri_lines : f:(Base.string -> Base.int -> Base.bool) -> cmd
Sourceval filter_map_lines : f:(Base.string -> Base.string Base.option) -> cmd
Sourceval filter_mapi_lines : f:(Base.string -> Base.int -> Base.string Base.option) -> cmd

File redirection

Sourceval write_stdout_to : Base.string -> cmd -> cmd
Sourceval append_stdout_to : Base.string -> cmd -> cmd
Sourceval write_stderr_to : Base.string -> cmd -> cmd
Sourceval append_stderr_to : Base.string -> cmd -> cmd
Sourceval read_stdin_from : Base.string -> cmd -> cmd
Sourceval stdout_to_stderr : cmd -> cmd
Sourceval stderr_to_stdout : cmd -> cmd

stdout_to_stderr and stderr_to_stdout are NOT composable! Think of these functions as each creating a new command with the given redirection.

Applying both will result in no output to either stdout or stderr. flip_stdout_and_stderr should be easy to write if anyone should need it.

Sourcemodule Infix : sig ... end

Built-in commands

Sourceval find : ?include_starting_dir:Base.bool -> ?ignore_hidden:Base.bool -> ?kind:[ `Files | `Directories ] -> ?name:Base.string -> ?depth:Base.int -> Base.string -> cmd

find lists files and/or directories, optionally filtering by name.

?depth: The maximum search depth, defaults to infinity.

?include_starting_dir: whether to include the starting directory passed into find. Defaults to false, notably different than the unix find utility.

Sourceval rg : ?in_:Base.string -> Base.string -> cmd

in_ is the directory that should be rg'd: rg <search> <in>. Without it, it'll filter stdin, just rg <search>

Sourceval rg_v : ?in_:Base.string -> Base.string -> cmd
Sourceval grep : ?in_:Base.string -> Base.string -> cmd
Sourceval cat : Base.string -> cmd
Sourceval less : cmd
Sourceval mkdir : Base.string -> cmd
Sourceval mkdir_p : Base.string -> cmd
Sourceval sort : cmd
Sourceval uniq : cmd
Sourceval shuf : cmd
Sourceval head : ?file:Base.string -> Base.int -> cmd
Sourceval tail : ?file:Base.string -> Base.int -> cmd
Sourceval tail_f : Base.string -> cmd
Sourceval echo : Base.string -> cmd
Sourceval cut' : ?complement:Base.unit -> ?d:Base.char -> Base.int Base.list -> cmd
Sourceval cut : ?d:Base.char -> Base.int -> cmd
Sourceval pwd : cmd
Sourceval tr_d : Base.string -> cmd

Misc

of_list emulates a Feather.cmd, each item in the list becomes a line on stdout.

lines splits a string into the list of its lines

Sourceval devnull : Base.string

devnull is easier to type than "/dev/null"

fzf runs the command, and fuzzy finds the stdout. Returns None if no item was chosen, Some str otherwise

Note that fzf is a way to to run a cmd and does not in itself return a cmd.

OCaml

Innovation. Community. Security.