From 05fdee1be781009f663fb995c26142002d612afa Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 16 Sep 2021 16:30:33 -0700 Subject: [PATCH] Continue passing -X / --no-init for less < v530 The less -F / --quit-if-one-screen option is buggy before v530. To work around this, pass --no-init less versions older than 530. The --no-init option was previously passed; it was removed in d15a51897d for mouse support. Unfortunately it looks like we can't have mouse support and --quit-if-one-screen on macOS shipped less (version 487). It's worth fixing this because otherwise history and help is just not printed on stock macOS. Relevant is https://unix.stackexchange.com/questions/107315/less-quit-if-one-screen-without-no-init Fixes #8157. --- CHANGELOG.rst | 1 + share/functions/__fish_print_help.fish | 10 +++++++++- share/functions/history.fish | 9 +++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) 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