Skip to content

Instantly share code, notes, and snippets.

@Milly
Created January 16, 2015 10:06
Show Gist options
  • Save Milly/40a69188224972b15fe4 to your computer and use it in GitHub Desktop.
Save Milly/40a69188224972b15fe4 to your computer and use it in GitHub Desktop.
color man command `cman` (16 or 256 colors)
# vim: set ft=sh:
function cman () {
local e=$'\e['
local highlight='1:31'
local underline='4;36'
local search='1;37;43'
[[ "${TERM}" == "${TERM/256}" ]] || {
highlight='1;38;05;166'
underline='4;38;05;75'
search='1;48;05;58'
}
case "${MANPAGER%% *}" in
less|'')
env \
LESS_TERMCAP_mb="${e}${highlight}m" \
LESS_TERMCAP_md="${e}${highlight}m" \
LESS_TERMCAP_me="${e}0m" \
LESS_TERMCAP_se="${e}0m" \
LESS_TERMCAP_so="${e}${search}m" \
LESS_TERMCAP_ue="${e}0m" \
LESS_TERMCAP_us="${e}${underline}m" \
MANPAGER="${MANPAGER:-less} -R" \
LANG=C \
man "$@" ;;
lv)
env \
LV="${LV} -c -Sh${highlight} -Su${underline} -Ss${search}" \
man "$@" ;;
*)
command man "$@" ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment