diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 92487824e..666ba7439 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -78,6 +78,7 @@ Interactive improvements - ``cd ""`` no longer crashes fish (:issue:`8147`). - Running a commandline consisting of just spaces now deletes an ephemeral (starting with space) history item again (:issue:`8232`). - Command substitutions no longer respect job control, instead running inside fish's own process group (:issue:`8172`). This more closely matches other shells, and improves :kbd:`Control-C` reliability inside a command substitution. +- ``history`` and ``__fish_print_help`` now properly support ``less`` before version 530, including the version that ships with macOS. (:issue:`8157`). New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index ce7ebe887..949faebfd 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -119,13 +119,21 @@ function __fish_print_help --description "Print help message for the specified f not isatty stdout and 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 test "$(less --version | string match -rg 'less (\d+)')" -lt 530 2>/dev/null + set lessopts "$lessopts"X + end + not set -qx LESS - and set -xl LESS isRF + 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 diff --git a/share/functions/history.fish b/share/functions/history.fish index 6bb378d25..c168b4e34 100644 --- a/share/functions/history.fish +++ b/share/functions/history.fish @@ -90,8 +90,13 @@ function history --description "display or manipulate interactive command histor # If the user hasn't preconfigured less with the $LESS environment variable, # we do so to have it behave like cat if output fits on one screen. - not set -qx LESS - and set -x LESS --quit-if-one-screen + if not set -qx LESS + set -x LESS --quit-if-one-screen + # Also set --no-init for less < v530, see #8157. + if test "$(less --version | string match -rg 'less (\d+)')" -lt 530 2>/dev/null + set -x LESS $LESS --no-init + end + end not set -qx LV # ask the pager lv not to strip colors and set -x LV -c