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.
This commit is contained in:
ridiculousfish 2021-09-16 16:30:33 -07:00
parent 5a6b966bfe
commit 05fdee1be7
3 changed files with 17 additions and 3 deletions

View file

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -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

View file

@ -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