Add zsh/lolcat.zsh rainbow helpers + document in README

This commit is contained in:
2026-06-24 09:12:17 -07:00
parent 2906352220
commit 4053acbbc0
2 changed files with 70 additions and 0 deletions
+39
View File
@@ -102,6 +102,45 @@ On top of stock YADR:
- Misc: `.rainbow_config.json` (rainbowstream), `.nanorc`, `.selected_editor`,
`.mplayer/config`, `.jigdo-lite`
## Rainbow output (lolcat)
`zsh/lolcat.zsh` wires [lolcat](https://github.com/jaseg/lolcat) (Debian's
`/usr/games/lolcat`, the truecolor C build) into a few shell helpers. lolcat
auto-detects a tty — it colorizes straight to the terminal but passes text
through plain when piped onward, so use `-f`/`--force` to colorize mid-pipeline.
### Opt-in, per command
Prefix any command to rainbow its output:
```sh
lol fastfetch
lol git log --oneline
lol ls -C # -C keeps columns: a piped ls otherwise goes single-column
lolf git diff | less -R # force color so it survives down a pipeline
```
### Shortcuts
```sh
rcat file.txt # rainbow cat
rls -la # rainbow ls, columns preserved
some-cmd | rless # rainbow + pager (less -R)
```
### Session toggle
Rainbow *all* shell stdout until you turn it off:
```sh
rainbow_on # everything is rainbow now
...
rainbow_off # back to normal
```
Novelty only: it garbles full-screen/interactive programs (vim, less, htop,
fzf, ssh) and the prompt, and buffers streaming output. Doesn't touch stderr.
## Upstream
Base is [skwp/dotfiles][yadr] (YADR — Yet Another Dotfiles Repo). All credit
+31
View File
@@ -0,0 +1,31 @@
# zsh/lolcat.zsh (drunkendotfiles) — auto-sourced via ~/.zshrc: for f in ~/.yadr/zsh/*.zsh
# Rainbow-output helpers built on lolcat (jaseg's C build at /usr/games/lolcat).
# This lolcat is truecolor and auto-detects a tty: it colorizes when writing
# straight to the terminal, but passes text through UNcolored when piped onward,
# so use -f/--force to colorize in the middle of a pipeline.
# Debian ships lolcat in /usr/games; make sure it's reachable in any shell.
[[ ":$PATH:" == *":/usr/games:"* ]] || export PATH="$PATH:/usr/games"
# --- opt-in: prefix ANY command to rainbow its output on the terminal --------
# lol ls -C lol fastfetch lol git log --oneline
# (The wrapped command sees a pipe, not a tty, so some tools drop their own
# colors/columns -- e.g. use `lol ls -C` to keep ls in columns.)
lol() { "$@" | lolcat; }
# Same, but force color so it survives further down a pipeline:
# lolf git diff | less -R
lolf() { "$@" | lolcat -f; }
# --- handy rainbow shortcuts for plain-text output ---------------------------
rcat() { lolcat "$@"; } # rcat file.txt (or: some-cmd | rcat)
rls() { ls -C "$@" | lolcat; } # rainbow ls, columns preserved
rless() { lolcat -f | less -R; } # pipe into me: some-cmd | rless
# --- whole-session "rainbow everything" toggle (NOVELTY) ---------------------
# Pipes the shell's stdout through lolcat until turned off. It WILL garble
# full-screen/interactive programs (vim, less, htop, fzf, ssh) and your prompt,
# and buffers streaming output. Use it for a burst of plain command output,
# then rainbow_off. Does not affect stderr.
rainbow_on() { [[ -n $RAINBOW_PIPE ]] && return; exec 3>&1; exec > >(lolcat -f); export RAINBOW_PIPE=1; }
rainbow_off() { [[ -z $RAINBOW_PIPE ]] && return; exec 1>&3 3>&-; unset RAINBOW_PIPE; }