Skip to content

Instantly share code, notes, and snippets.

@chip
Last active January 19, 2026 17:35
Show Gist options
  • Select an option

  • Save chip/8b04cca445c580933c906a779aebb90e to your computer and use it in GitHub Desktop.

Select an option

Save chip/8b04cca445c580933c906a779aebb90e to your computer and use it in GitHub Desktop.
riz zsh function - ruby docs with color
# This file is located at ~/.zsh/ruby.zsh and sourced from ~/.zshrc
# chruby settings
source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby ruby-3.4.8
# ruby env vars for installing docs
export RUBY_CONFIGURE_OPTS="--with-libyaml-dir=$(/opt/homebrew/bin/brew --prefix libyaml) --enable-install-doc"
export RI_BASE_DIR="$HOME/.local/share/rdoc"
# Ruby docs with color
riz() {
[[ -z "$1" ]] && echo "riz needs a Ruby method or class as an argument (Array, Array#map, map)" && return 0
# pass argument to Ruby documation API cli
# remove backspace characters
# escape occurrences of \'s (apostrophe s)
# escape occurrences of \'t (apostrophe t)
# pipe documentation to bat using ruby language highlighting
ri "$1" | \
perl -pe 's/.?\x08//g' | \
sed "s/'\(s\) /'\\\\''\1 /g" | \
sed "s/'\(t\) /'\\\\''\1 /g" | \
bat -l ruby
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment