Fix the doc command for users of BSD man

This commit uses options and flags that will work on both the BSD and
the `man-db` implementations, however those changes remain unportable as
the POSIX standard only defines a single `-k` flag for the utility,
which we don't need.

The call to the `col` utility has also been replaced by a call to `sed`,
as the former is only shipped on systems that have the `nroff` formatter
installed.
This commit is contained in:
Frank LENORMAND 2016-11-03 14:57:55 +03:00
parent 6347787cf2
commit 277117f64b

View File

@ -1,19 +1,21 @@
decl str docsclient
def -hidden -params 1..2 _doc-open %{
%sh{
manout=$(mktemp /tmp/kak-man-XXXXXX)
colout=$(mktemp /tmp/kak-man-XXXXXX)
MANWIDTH=${kak_window_width} man "$1" > $manout
retval=$?
# Those options are handled by the `man-db` implementation
export MAN_KEEP_FORMATTING=y
export MANWIDTH=${kak_window_width}
col -b -x > ${colout} < ${manout}
rm ${manout}
# The BSD implementation requires an `-l` flag to detect a filetype as argument
if man -l "$1" > "${manout}"; then
sed -i 's/.\x8//g' "${manout}"
if [ "${retval}" -eq 0 ]; then
printf %s\\n "
edit! -scratch '*doc*'
exec |cat<space>${colout}<ret>gg
nop %sh{rm ${colout}}
exec |cat<space>${manout}<ret>gg
nop %sh{rm ${manout}}
set buffer filetype man
"
@ -23,7 +25,7 @@ def -hidden -params 1..2 _doc-open %{
fi
else
printf %s\\n "echo -color Error %{doc '$@' failed: see *debug* buffer for details}"
rm ${colout}
rm ${manout}
fi
}
}