Skip to content
Albert Alef edited this page Feb 3, 2026 · 6 revisions

RubyShell

The Rubyist way to write shell scripts.

RubyShell is a Ruby gem that allows shell commands to be called as natural Ruby methods. Instead of concatenating strings and escaping arguments, you write readable Ruby code that seamlessly integrates with shell commands.

sh do
  cd "/var/log" do
    cat("syslog").lines.first(10).each { |line| puts line }
  end
end

Why RubyShell?

  • Readable syntax - Shell commands become Ruby methods with proper argument handling
  • Error handling - Real exceptions instead of silent failures
  • Ruby integration - Use .map, .select, .each on command output
  • Argument parsing - Hash options become flags automatically (all: true--all)
  • Output parsing - Automatic JSON, YAML, and CSV parsing with _parse
  • Scoped directories - cd with blocks that auto-restore the working directory

Pages

Getting Started

Core Features

Reference

Extras

  • Snippets - Zsh plugin for terminal integration
  • Examples - Real-world usage examples

Roadmap

Quick Example

require 'rubyshell'

sh do
  # Git workflow with error handling
  begin
    git("pull", rebase: true)
    rake("spec")
    git("push")
  rescue RubyShell::CommandError => e
    puts "Failed: #{e.stderr}"
  end
end

Links

Clone this wiki locally