Last active
September 3, 2026 18:55
-
-
Save chip/8b04cca445c580933c906a779aebb90e to your computer and use it in GitHub Desktop.
riz zsh function - Ruby API reference front end, WITH COLOR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 API reference front end, WITH COLOR | |
| riz() { | |
| [[ -z "$1" ]] && echo "riz needs a Ruby method or class as an argument (Array, Array#map, map)" && return 0 | |
| # ri is passed an argument | |
| # perl removes backspace characters | |
| # sed escapes occurrences of \'s (apostrophe s) | |
| # sed escapes 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 | |
| } |
Author
Author
I just noticed that my bat config, located at `~/.config/bat/config, included the following necessary flags:
--style="plain"
--theme="Catppuccin Mocha"
--italic-text=always
Your local configuration would require you to pass these flags from within the riz function if your bat config differs from mine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
riz Arrayfrom my terminal would display this: