From 0fea1dae8c560cd06f161e8be3c480531a0f9b94 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 3 Oct 2024 11:19:30 +0200 Subject: [PATCH] __fish_print_help: Make formatting more man-like 1. Leave the indentation 2. Leave the "NAME" header - without the first line would be unindented 3. Leave the "SYNOPSIS" header We use $MANPAGER here, so it should be formatted like a manpage. The alternative is to write special docs for this use-case, which would be shorter and point towards the full man page. Fixes #10625 --- share/functions/__fish_print_help.fish | 47 ++++++++++++-------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index 79b77cd15..352070d6d 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -92,9 +92,7 @@ function __fish_print_help --description "Print help message for the specified f # Remove man's bolding set -l name (string replace -ra '(.)'\b'.' '$1' -- $line) # We start after we have the name - contains -- $name NAME; and set have_name 1; and continue - # We ignore the SYNOPSIS header - contains -- $name SYNOPSIS; and continue + contains -- $name NAME; and set have_name 1 # Everything after COPYRIGHT is useless contains -- $name COPYRIGHT; and break @@ -123,28 +121,27 @@ function __fish_print_help --description "Print help message for the specified f end end end - end | string replace -ra '^ ' '' | - begin - set -l pager (__fish_anypager --with-manpager) - and isatty stdout - or set pager cat # cannot use a builtin here + end | begin + set -l pager (__fish_anypager --with-manpager) + and isatty stdout + or set pager cat # cannot use a builtin here - # similar to man, but add -F to quit paging when the help output is brief (#6227) - # Also set -X for less < v530, see #8157. - set -l lessopts isRF - if type -q less; and test (less --version | string match -r 'less (\d+)')[2] -lt 530 2>/dev/null - set lessopts "$lessopts"X - end - - not set -qx LESS - and set -xl LESS $lessopts - - # less options: - # -i (--ignore-case) search case-insensitively, like man - # -s (--squeeze-blank-lines) not strictly necessary since we already do that above - # -R (--RAW-CONTROL-CHARS) to display colors and such - # -F (--quit-if-one-screen) to maintain the non-paging behavior for small outputs - # -X (--no-init) do not clear the screen, necessary for less < v530 or else short output is dropped - $pager + # similar to man, but add -F to quit paging when the help output is brief (#6227) + # Also set -X for less < v530, see #8157. + set -l lessopts isRF + if type -q less; and test (less --version | string match -r 'less (\d+)')[2] -lt 530 2>/dev/null + set lessopts "$lessopts"X end + + not set -qx LESS + and set -xl LESS $lessopts + + # less options: + # -i (--ignore-case) search case-insensitively, like man + # -s (--squeeze-blank-lines) not strictly necessary since we already do that above + # -R (--RAW-CONTROL-CHARS) to display colors and such + # -F (--quit-if-one-screen) to maintain the non-paging behavior for small outputs + # -X (--no-init) do not clear the screen, necessary for less < v530 or else short output is dropped + $pager + end end