Skip to content

Instantly share code, notes, and snippets.

@rfaulhaber
Created August 6, 2023 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfaulhaber/6d98d6ad5d03bf9a2692ade295a19ebb to your computer and use it in GitHub Desktop.
Save rfaulhaber/6d98d6ad5d03bf9a2692ade295a19ebb to your computer and use it in GitHub Desktop.
Port of oh-my-zsh's colored_man_pages in Nushell, allowing for an overridable theme.
export def colored_man_pages [
--theme: record, # Theme you want to color the manpage with. Should be a record with attributes mb, md, me, so, se, us, ue, which correspond to LESS_TERMCAP variables
...args # Arguments passed to `man`
] {
# we create a private extern for `man` so we can pass it a list of strings later
extern man [...args: string]
let colors = if $theme != null {
$theme
} else {
{
mb: (ansi red_bold),
md: (ansi red_bold),
me: (ansi reset)
so: (ansi { fg: 'yellow_bold', bg: 'blue', attr: 'b' })
se: (ansi reset),
us: (ansi green_bold),
ue: (ansi reset)
}
}
let less_env = ($colors | columns | reduce -f {} { |c, all| $all | insert $"LESS_TERMCAP_($c)" ($colors | get $c) })
with-env $less_env { ^man $args }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment