HN
Today

Rubish: A Unix shell written in pure Ruby

Rubish is a new Unix shell crafted entirely in pure Ruby, aiming for complete Bash compatibility while deeply integrating Ruby's powerful features. It allows users to run existing Bash scripts seamlessly and enhance them with Ruby's syntax, method chaining, and iterator blocks. This project offers a fascinating technical dive into reimagining core system tools with modern language capabilities, appealing to developers who appreciate elegant language integration and efficient scripting.

13
Score
2
Comments
#2
Highest Rank
12h
on Front Page
First Seen
May 23, 9:00 AM
Last Seen
May 23, 8:00 PM
Rank Over Time
622577101718212627

The Lowdown

Rubish is an innovative project that re-implements a Unix shell entirely in pure Ruby. Its core concept involves parsing traditional shell syntax, compiling it into Ruby code, and then executing it via the Ruby Virtual Machine. The ambitious goal is to be fully Bash-compatible, meaning existing Bash scripts should run without modification, while simultaneously offering deep integration with Ruby's powerful features.

Key features and functionalities include:

  • Full Bash and Partial Zsh Compatibility: Rubish aims to execute existing Bash scripts flawlessly and incorporates several Zsh-like features, such as setopt/unsetopt and abbreviated path expansion.
  • Deep Ruby Integration: It allows seamless mixing of shell commands and Ruby code. Users can leverage Ruby's blocks, iterators, and libraries directly within shell scripts.
  • Enhanced Scripting with Ruby: Introduces Ruby conditions in if, while, and until statements, method call style for commands (e.g., ls('-la')), and method chaining for piping (ls().sort.uniq).
  • Inline Ruby Evaluation: Lines starting with a capital letter are automatically evaluated as Ruby code, enabling direct use of Ruby classes, methods, and expressions.
  • Customization and Control: Supports Ruby-style function definitions (def...end) and allows for dynamic, programmatic prompts defined as Ruby functions.
  • Performance and Security: Features lazy_load for deferring slow shell initializations to background threads, ensuring fast startup. A restricted mode (rubish -r) disables Ruby integration for executing untrusted scripts safely.
  • Embeddable API: Rubish exposes a public API, allowing other Ruby programs, such as terminal emulators or IDE plugins, to drive a Rubish session in-process without relying on fork/exec or JSON serialization.

Rubish presents a compelling alternative for developers who live in the Ruby ecosystem or seek a more modern, programmable shell experience. Its combination of robust Bash compatibility with the expressive power of Ruby positions it as a significant tool for advanced scripting and system interaction.