Skip to content

🐒 A Gleam library for cross-platform shell operations

License

Notifications You must be signed in to change notification settings

tynanbe/shellout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

shellout 🐒

Hex Package Hex Docs License Build

A Gleam library for cross-platform shell operations.


Usage

Example

β€’ In my_project/src/my_project.gleam

import gleam/dict
import gleam/io
import gleam/result
import shellout.{type Lookups}

pub const lookups: Lookups = [
  #(
    ["color", "background"],
    [
      #("buttercup", ["252", "226", "174"]),
      #("mint", ["182", "255", "234"]),
      #("pink", ["255", "175", "243"]),
    ],
  ),
]

pub fn main() {
  shellout.arguments()
  |> shellout.command(run: "ls", in: ".", opt: [])
  |> result.map(with: fn(output) {
    io.print(output)
    0
  })
  |> result.map_error(with: fn(detail) {
    let #(status, message) = detail
    let style =
      shellout.display(["bold", "italic"])
      |> dict.merge(from: shellout.color(["pink"]))
      |> dict.merge(from: shellout.background(["brightblack"]))
    message
    |> shellout.style(with: style, custom: lookups)
    |> io.print_error
    status
  })
  |> result.unwrap_both
  |> shellout.exit
}

🐚 You can test the above example with your shell!

β€’ In your terminal

> cd my_project
> gleam run -- -lah
# ..
> gleam run -- --lah
# ..
> gleam run --target=javascript -- -lah
# ..
> gleam run --target=javascript -- --lah
# ..

Installation

As a dependency of your Gleam project

β€’ Add shellout to gleam.toml

gleam add shellout

As a dependency of your Mix project

β€’ Add shellout to mix.exs

defp deps do
  [
    {:shellout, "~> 1.6"},
  ]
end

As a dependency of your Rebar3 project

β€’ Add shellout to rebar.config

{deps, [
  {shellout, "1.6.0"}
]}.