The Ruby SHell
Ruby is my goto language (pun kinda intended). I want full control over my tools and I like challenges that I can tinker with late at night. This is an incomplete project continually being improved. Feel free to add suggestions or code.
Simple. One file. Minimum external requirements.
Clone this repo and drop rsh
into your preferred bin directory. Drop .rshrc
into your home directory and edit as you see fit.
Or simply gem install ruby-shell
.
- Aliases (called nicks in rsh) - both for commands and general nicks
- Syntax highlighting, matching nicks, system commands and valid dirs/files
- Tab completions for nicks, system commands, command switches and dirs/files
- Tab completion presents matches in a list to pick from
- When you start to write a command, rsh will suggest the first match in the history and present that in "toned down" letters - press the arrow right key to accept the suggestion.
- Writing a partial command and pressing
UP
will search history for matches. Go down/up in the list and pressTAB
orENTER
to accept,Ctrl-g
orCtrl-c
to discard - History with editing, search and repeat a history command (with
!
) - Config file (.rshrc) updates on exit (with Ctrl-d) or not (with Ctrl-e)
- Set of simple rsh specific commands like nick, nick?, history and rmhistory
- rsh specific commands and full set of Ruby commands available via :
- All colors are themeable in .rshrc (see github link for possibilities)
- Copy current command line to primary selection (paste w/middle button) with
Ctrl-y
Special functions/integrations:
- Use
r
to launch rtfm (https://github.com/isene/RTFM) - if you have it installed - Use
f
to launch fzf (https://github.com/junegunn/fzf) - if you have it installed - Use
=
followed by xrpn commands separated by commas (https://github.com/isene/xrpn) - Use
:
followed by a Ruby expression to access the whole world of Ruby
Special commands:
:nick 'll = ls -l'
to make a command alias (ll) point to a command (ls -l):gnick 'h = /home/me'
to make a general alias (h) point to something (/home/me):nick?
will list all command nicks and general nicks (you can edit your nicks in .rshrc):history
will list the command history, while:rmhistory
will delete the history:version
Shows the rsh version number and the last published gem file version:help
will display this help text
While you cd
around to different directories, you can see the last 10 directories visited via the command :dirs
or the convenient shortcut #
. Entering the number in the list (like 6
and ENTER) will jump you to that directory. Entering -
will jump you back to the previous dir (equivalent of 1
. Entering ~
will get you to your home dir. If you want to bookmark a special directory, you can do that via a general nick like this: :gnick "x = /path/to/a/dir/"
- this would bookmark the directory to the single letter x
.
Add command nicks (aliases) with :nick "some_nick = some_command"
, e.g. :nick "ls = ls --color"
. Add general nicks that will substitute anything on a command line (not just commands) like this :gnick "some_gnick = some_command"
, e.g. :gnick "x = /home/user/somewhere"
. List (g)nicks with :nick?
. Remove a nick with :nick "-some_command"
, e.g. :nick "-ls"
to remove an ls
nick. Same for gnicks.
You can tab complete almost anything. Hitting TAB
will try to complete in this priority: nicks, gnicks, commands, dirs/files. Hitting TAB
after a -
will list the command switches for the preceding command with a short explanation (from the command's --help), like this ls -
(TAB
) will list all the switches/options for the ls
command. You can add to (or subtract from) the search criteria while selecting possible matches - hit any letter to specify the search, while backspace removes a letter from the search criteria.
Hitting Shift-TAB will do a similar search through the command history - but with a general match of the search criteria (not only matching at the start).
If you press ENTER
after writing or tab-completing to a file, rsh will try to open the file in the user's EDITOR of choice (if it is a valid text file) or use xdg-open
to open the file using the correct program. If you, for some reason want to use run-mailcap
instead of xdg-open
as the file opener, simply add @runmailcap = true
to your .rshrc
.
Show the history with :history
. Redo a history command with an exclamation mark and the number corresponding to the position in the history, like !5
would do the 5th history command again.
rsh is integrated with the rtfm file manager, with fzf and with the programming language XRPN.
Just enter the command r
and rtfm will be launched - and when you quit the file manager, you will drop back into rsh in the directory you where you exited rtfm.
Enter the command f
to launch the fuzzy finder - select the directory/file you want, press ENTER
and you will find yourself in the directory where that item resides.
If you start a line with "=", the rest of the line will be interpreted as an XRPN program. This gives you the full power of XRPN right at your fingertips. You can do simple stuff like this: =13,23,*,x^2
and the answer to (13 * 23)^2
will be given (89401) in the format that you have set in your .xrpn/conf
. Or you can do more elaborate stuff like =fix 6,5,sto c,time,'Time now is: ',atime,aview,pse,fix 0,lbl a,rcl c,prx,dse c,gto a
. Go crazy. Use single-quotes for any Alpha entry.
rsh will highlight nicks, gnicks, commands and dirs/files as they are written on the command line.
In the supplied .rshrc
, you will find a set of colors that you can change:
Variable | Description |
---|---|
@c_prompt |
Color for basic prompt |
@c_cmd |
Color for valid command |
@c_nick |
Color for matching nick |
@c_gnick |
Color for matching gnick |
@c_path |
Color for valid path |
@c_tabselect |
Color for selected tabcompleted item |
@c_taboption |
Color for unselected tabcompleted item |
@c_stamp |
Color for time stamp/command |
.rshrc
is the configuration file for rsh and it is located in your home directory. It is created when you first start rsh and you can modify it to suit your needs. A more detailed .rshrc is found in the the rsh github repo - you can drop this into your home dir if you like. Set the basic environment variables like this:
ENV["EDITOR"] = "vim"
ENV["MANPAGER"] = "vim +MANPAGER -"
Also, a special variable for better LS_COLOR setup:
@lscolors = "/home/geir/.local/share/lscolors.sh"
Point @lscolors
to a file that sets your LS_COLORS variable. Use my extended LS_COLORS setup to make this really fancy.
You can add any Ruby code to your .rshrc.
By entering :some-ruby-command
you have full access to the Ruby universe right from your command line. You can do anything from :puts 2 + 13
or :if 0.7 > Math::sin(34) then puts "OK" end
or whatever tickles you fancy.
Lots. Of. Stuff.
Forget it.