-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Albert Alef edited this page Feb 3, 2026
·
6 revisions
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- Readable syntax - Shell commands become Ruby methods with proper argument handling
- Error handling - Real exceptions instead of silent failures
-
Ruby integration - Use
.map,.select,.eachon command output -
Argument parsing - Hash options become flags automatically (
all: true→--all) -
Output parsing - Automatic JSON, YAML, and CSV parsing with
_parse -
Scoped directories -
cdwith blocks that auto-restore the working directory
- Installation - How to install and require RubyShell
- Basic Usage - Core concepts and first steps
- Arguments and Options - Flags, options, and argument handling
- Command Chaining - Pipes, redirects, and building pipelines
- Error Handling - Working with CommandError exceptions
-
Overwritten Methods - Special behavior for
cd,ls, andclear - Debugging - Debug mode and logging
- Next Steps - Planned features and improvements
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