# zsh/lolcat.zsh (drunkendotfiles) — auto-sourced via ~/.zshrc: for f in ~/.yadr/zsh/*.zsh # Rainbow-output helpers built on lolcat. Active build is jaseg's C lolcat at # /usr/local/bin/lolcat (faster; built from source, ahead of Debian's busyloop # Ruby /usr/games/lolcat on PATH). Both support -f/--force-color + tty # auto-detect, so these helpers work with either. # 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; }