From 277117f64b67b0f80d8eb26e4bcf0956fc2ca499 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 3 Nov 2016 14:57:55 +0300 Subject: [PATCH] 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. --- rc/core/doc.kak | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/rc/core/doc.kak b/rc/core/doc.kak index 16d5393c..e9a4eff4 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -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${colout}gg - nop %sh{rm ${colout}} + exec |cat${manout}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 } }