Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
9b119866
Unverified
Commit
9b119866
authored
Nov 12, 2020
by
ratijas
Committed by
GitHub
Nov 12, 2020
Browse files
refactor(colored-man-pages): move nroff wrapper and refactor logic in `colored` function (#9437)
parent
51772732
Changes
3
Hide whitespace changes
Inline
Side-by-side
plugins/colored-man-pages/README.md
View file @
9b119866
...
@@ -16,3 +16,17 @@ You can also try to color other pages by prefixing the respective command with `
...
@@ -16,3 +16,17 @@ You can also try to color other pages by prefixing the respective command with `
```
zsh
```
zsh
colored git
help
clone
colored git
help
clone
```
```
## Customization
The plugin declares global associative array
`less_termcap`
, which maps termcap capabilities to escape
sequences for the
`less`
pager. This mapping can be further customized by the user after the plugin is
loaded. Check out sources for more.
For example:
`less_termcap[md]`
maps to
`LESS_TERMCAP_md`
which is the escape sequence that tells
`less`
how to print something in bold. It's currently shown in bold red, but if you want to change it, you
can redefine
`less_termcap[md]`
in your zshrc file, after OMZ is sourced:
```
zsh
less_termcap[md]
=
"
${
fg_bold
[blue]
}
"
# this tells less to print bold text in bold blue
```
plugins/colored-man-pages/colored-man-pages.plugin.zsh
View file @
9b119866
if
[[
"
$OSTYPE
"
=
solaris
*
]]
# Requires colors autoload.
then
# See termcap(5).
if
[[
!
-x
"
$HOME
/bin/nroff"
]]
then
# Set up once, and then reuse. This way it supports user overrides after the
mkdir
-p
"
$HOME
/bin"
# plugin is loaded.
cat
>
"
$HOME
/bin/nroff"
<<
EOF
typeset
-AHg
less_termcap
#!/bin/sh
if [ -n "
\$
_NROFF_U" -a "
\$
1,
\$
2,
\$
3" = "-u0,-Tlp,-man" ]; then
# bold & blinking mode
shift
less_termcap[mb]
=
"
${
fg_bold
[red]
}
"
exec /usr/bin/nroff -u
\$
_NROFF_U "
\$
@"
less_termcap[md]
=
"
${
fg_bold
[red]
}
"
fi
less_termcap[me]
=
"
${
reset_color
}
"
#-- Some other invocation of nroff
# standout mode
exec /usr/bin/nroff "
\$
@"
less_termcap[so]
=
"
${
fg_bold
[yellow]
}${
bg
[blue]
}
"
EOF
less_termcap[se]
=
"
${
reset_color
}
"
chmod
+x
"
$HOME
/bin/nroff"
# underlining
fi
less_termcap[us]
=
"
${
fg_bold
[green]
}
"
fi
less_termcap[ue]
=
"
${
reset_color
}
"
# Absolute path to this file's directory.
typeset
__colored_man_pages_dir
=
"
${
0
:A:h
}
"
function
colored
()
{
function
colored
()
{
command env
\
local
-a
environment
LESS_TERMCAP_mb
=
$(
printf
"
\e
[1;31m"
)
\
LESS_TERMCAP_md
=
$(
printf
"
\e
[1;31m"
)
\
# Convert associative array to plain array of NAME=VALUE items.
LESS_TERMCAP_me
=
$(
printf
"
\e
[0m"
)
\
local
k v
LESS_TERMCAP_se
=
$(
printf
"
\e
[0m"
)
\
for
k v
in
"
${
(@kv)less_termcap
}
"
;
do
LESS_TERMCAP_so
=
$(
printf
"
\e
[1;44;33m"
)
\
environment+
=(
"LESS_TERMCAP_
${
k
}
=
${
v
}
"
)
LESS_TERMCAP_ue
=
$(
printf
"
\e
[0m"
)
\
done
LESS_TERMCAP_us
=
$(
printf
"
\e
[1;32m"
)
\
PAGER
=
"
${
commands
[less]
:-
$PAGER
}
"
\
# Prefer `less` whenever available, since we specifically configured
_NROFF_U
=
1
\
# environment for it.
PATH
=
"
$HOME
/bin:
$PATH
"
\
environment+
=(
PAGER
=
"
${
commands
[less]
:-
$PAGER
}
"
)
"
$@
"
# See ./nroff script.
if
[[
"
$OSTYPE
"
=
solaris
*
]]
;
then
environment+
=(
PATH
=
"
${
__colored_man_pages_dir
}
:
$PATH
"
)
fi
command env
$environment
"
$@
"
}
}
# Colorize man and dman/debman (from debian-goodies)
# Colorize man and dman/debman (from debian-goodies)
function
man
\
function
man
\
dman
\
dman
\
debman
{
debman
{
colored
$0
"
$@
"
colored
$0
"
$@
"
}
}
plugins/colored-man-pages/nroff
0 → 100755
View file @
9b119866
#!/bin/sh
# The whole point of this wrapper is to replace emboldening factor -u0 with
# -u1 under certain circumstances on Solaris.
if
[
"
$1
,
$2
,
$3
"
=
"-u0,-Tlp,-man"
]
;
then
shift
exec
/usr/bin/nroff
-u1
"
$@
"
else
# Some other invocation of nroff
exec
/usr/bin/nroff
"
$@
"
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment