Project

rubsh

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
A ruby shell
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

Rubsh

Rubsh was created to be a native shell for ruby users. A irb which can also be used as a normal shell without the akwardness of some of the features of bash and other shells, and with the power of ruby.

Installation

sudo gem source -a http://gemcutter.org
sudo gem install rubsh

Run rubsh on the commandline. Type help for a quick overview of usage.

Features

  • readline support

  • tab completion

  • aliases

  • commandline history

Usage

aliases

ralias aliases a command.

Example:

ralias 'ls ls -Gh'

Currently an alias will not be parsed to include other aliases. i.e. doing ralias 'ls ls -Gh' followed by ralias 'll ls -l' will not get you ‘ls -lGh’

.rubsh/rc.rb

Define your own functions, aliases etc in the rc file. It’s included to the environment.

Shortcuts

While normal commands as ‘ls’ etc work transparantly, you can also do things like:

'*'.ls

shortcut for Dir.glob(…)

'*'.ls.du

Does du on all the results

It also takes arguments:

'*'.ls.du(:sh)

is equivalent to du -sh *

Prompt

use ENV to set your prompt. see ‘help prompt’ for options from within the shell.

%h  - hostname
%u  - the username of the current user
%w  - the current working directory, with $HOME abbreviated with a tilde
%W  - the basename of the current working directory, with $HOME abbreviated
with a tilde
%Cb - blue color
%Cc - cyan color
%Cg - green color
%CC - color reset
%t  - the current time in 24-hour HH:MM:SS format
%%  - literal %
%$  - if the effective UID is 0, a #, otherwise a $

Example: ENV['PR1'] = "[%u@%h]--(%t)\n\r[%w]%$ "

Ruby command functions

Rubsh keeps one Ruby context for the shell session. Define a function over multiple lines, then use it as a command or inside backtick command substitution:

def foo
  return "ok"
end

echo `foo` | tee out.txt

The example prints ok and writes ok\n to out.txt. Function arguments are the command arguments. A returned string becomes command output; puts writes directly to the command’s output stream.

Pipelines

Commands are parsed into argv arrays, so quotes and escaped spaces remain one argument. The pipe operator connects command stages, including Ruby functions and external programs. Backticks run a nested Rubsh command and substitute its captured output, with a trailing newline removed.

Rubsh intentionally does not implement job control, background jobs, heredocs, redirects, or &&/|| conditionals. Stateful commands such as cd run in the shell process so directory changes persist.