-
Notifications
You must be signed in to change notification settings - Fork 4
Snippets
Albert Álef edited this page Feb 3, 2026
·
3 revisions
Useful code snippets for integrating RubyShell with your environment.
This Zsh plugin allows you to run RubyShell commands directly in your terminal with the rb prefix:
_rb_parser() {
local ORIGINAL_BUFFER="$BUFFER"
# Check if the command starts with 'rb '
if [[ "$BUFFER" == rb\ * ]]; then
local rb_cmd="${BUFFER#rb }"
local rest=""
# Check for shell operators
if [[ "$rb_cmd" =~ ^(.+?)(\ *[\|><\&].*)$ ]]; then
rb_cmd="${match[1]}"
rest="${match[2]}"
fi
# Modify buffer to execute Ruby with RubyShell
BUFFER=" ruby -r rubyshell -e \"extend RubyShell::Executor; puts($rb_cmd)\"$rest"
# Add original command to history (for recall)
print -s "$ORIGINAL_BUFFER"
fi
zle accept-line
}
zle -N _rb_parser
bindkey '^M' _rb_parserAfter adding the plugin to your .zshrc:
# List files and count lines
rb ls.lines.count
# Pipe to other commands
rb ls.lines.count | cat
# Redirect to file
rb ls.lines.count > count.txt
# Use with grep
rb git("status", porcelain: true).lines.count- Intercepts commands starting with
rb - Preserves the original command in history
- Wraps Ruby code with RubyShell executor
- Handles shell operators (pipes, redirects)
- Executes via
ruby -r rubyshell -e
Add to your .irbrc to have RubyShell available in all IRB sessions:
require "rubyshell/tty/irb"Add to your .pryrc:
coming soonNext: Examples