Files
drunkendotfiles/zsh/lolcat.zsh
T

34 lines
1.9 KiB
Bash

# zsh/lolcat.zsh (drunkendotfiles) — auto-sourced via ~/.zshrc: for f in ~/.yadr/zsh/*.zsh
# Rainbow-output helpers built on lolcat = Debian's busyloop Ruby build at
# /usr/games/lolcat (upstream github.com/busyloop/lolcat; 24-bit truecolor).
# It auto-detects a tty, so use -f/--force-color to colorize mid-pipeline.
# 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; }