From 9b42051ba7f806e90ecbd78c385f2fe4275e326d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 9 Nov 2025 11:49:05 +0100 Subject: [PATCH] functions/man: don't export MANPATH unnecessarily We always try to prepend our man path to $MANPATH before calling man. But this is not necessary when we're gonna display the output of "status get-file man/man1/abbr.1". Overriding man pages can cause issues like https://github.com/fish-shell/fish-shell/issues/11472 https://gitlab.com/man-db/man-db/-/merge_requests/15 which by themselves are maybe not enough reason to avoid exporting MANPATH, but given that embedded man pages might become the only choice in future (see #12037), we should reduce the scope of our custom MANPATH. --- share/functions/man.fish | 60 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/share/functions/man.fish b/share/functions/man.fish index 3cb99e289..db695e050 100644 --- a/share/functions/man.fish +++ b/share/functions/man.fish @@ -6,38 +6,35 @@ if not command -qs man end function man - # Work around the "builtin" manpage that everything symlinks to, - # by prepending our fish datadir to man. This also ensures that man gives fish's - # man pages priority, without having to put fish's bin directories first in $PATH. - - # Preserve the existing MANPATH, and default to the system path (the empty string). set -l manpath - if set -q MANPATH - set manpath $MANPATH - else if set -l p (command man -p 2>/dev/null) - # NetBSD's man uses "-p" to print the path. - # FreeBSD's man also has a "-p" option, but that requires an argument. - # Other mans (men?) don't seem to have it. - # - # Unfortunately NetBSD prints things like "/usr/share/man/man1", - # while not allowing them as $MANPATH components. - # What it needs is just "/usr/share/man". - # - # So we strip the last component. - # This leaves a few wrong directories, but that should be harmless. - set manpath (string replace -r '[^/]+$' '' $p) - else - set manpath '' - end - # Notice the shadowing local exported copy of the variable. - set -lx MANPATH $manpath - - # Prepend fish's man directory if available. if not __fish_is_standalone - set -l fish_manpath $__fish_data_dir/man - if test -d $fish_manpath - set MANPATH $fish_manpath $MANPATH - end + and set -l fish_manpath (path filter -d $__fish_data_dir/man) + # Prepend fish's man directory if available. + + # Work around the "builtin" manpage that everything symlinks to, + # by prepending our fish datadir to man. This also ensures that man gives fish's + # man pages priority, without having to put fish's bin directories first in $PATH. + + # Preserve the existing MANPATH, and default to the system path (the empty string). + set manpath $fish_manpath ( + if set -q MANPATH + string join -- \n $MANPATH + else if set -l p (command man -p 2>/dev/null) + # NetBSD's man uses "-p" to print the path. + # FreeBSD's man also has a "-p" option, but that requires an argument. + # Other mans (men?) don't seem to have it. + # + # Unfortunately NetBSD prints things like "/usr/share/man/man1", + # while not allowing them as $MANPATH components. + # What it needs is just "/usr/share/man". + # + # So we strip the last component. + # This leaves a few wrong directories, but that should be harmless. + string replace -r '[^/]+$' '' $p + else + echo '' + end + ) end if test (count $argv) -eq 1 @@ -54,6 +51,9 @@ function man (string escape --style=regex -- $basename) __fish_man __fish_with_status functions --erase __fish_man else + set -q manpath[1] + and set -lx MANPATH $manpath + command man $argv end end