Created
August 6, 2023 15:52
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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