From d540b9f924d633d185cfc7b04b3f01c680361f24 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 1 Dec 2015 12:09:26 +0300 Subject: [PATCH] Display the page number in the man page completions --- rc/man.kak | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/rc/man.kak b/rc/man.kak index 03c80070..b71cccc4 100644 --- a/rc/man.kak +++ b/rc/man.kak @@ -38,13 +38,23 @@ def -shell-params \ prefix=${1:0:${kak_pos_in_token}} for page in /usr/share/man/*/${prefix}*.[1-8]*; do candidate=$(basename ${page%%.[1-8]*}) + pagenum=$(sed -r 's,^.+/.+\.([1-8][^.]*)\..+$,\1,' <<< $page) case $candidate in *\*) ;; - *) echo $candidate ;; + *) echo $candidate\($pagenum\);; esac done } \ man -docstring "Manpages viewer wrapper" %{ %sh{ - [ -z "$@" ] && set -- "$kak_selection" - echo "eval -try-client %opt{docsclient} _man $@" + subject=${@-$kak_selection} + pagenum="" + + ## The completion suggestions display the page number, strip them if present + if [[ $subject =~ [a-zA-Z_-]+\([^\)]+\) ]]; then + pagenum=${subject##*\(} + pagenum=${pagenum:0:$((${#pagenum} - 1))} + subject=${subject%%\(*} + fi + + echo "eval -try-client %opt{docsclient} _man $pagenum $subject" } }