2025-09-29 09:30:35 +02:00
|
|
|
# localization: skip(uses-apropos)
|
|
|
|
|
|
2025-01-19 18:34:42 +01:00
|
|
|
if not command -qs man
|
|
|
|
|
# see #5329 and discussion at https://github.com/fish-shell/fish-shell/commit/13e025bdb01cc4dd08463ec497a0a3495873702f
|
|
|
|
|
exit
|
|
|
|
|
end
|
2018-11-17 22:03:45 -06:00
|
|
|
|
2025-09-29 09:30:35 +02:00
|
|
|
function man
|
2025-01-19 18:34:42 +01:00
|
|
|
# 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.
|
2025-04-12 20:19:15 +02:00
|
|
|
if set -q __fish_data_dir[1]
|
|
|
|
|
set -l fish_manpath $__fish_data_dir/man
|
|
|
|
|
if test -d $fish_manpath
|
|
|
|
|
set MANPATH $fish_manpath $MANPATH
|
|
|
|
|
end
|
2025-01-19 18:34:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if test (count $argv) -eq 1
|
|
|
|
|
# Some of these don't have their own page,
|
|
|
|
|
# and adding one would be awkward given that the filename
|
|
|
|
|
# isn't guaranteed to be allowed.
|
|
|
|
|
# So we override them with the good name.
|
|
|
|
|
switch $argv
|
2025-08-29 11:40:42 +02:00
|
|
|
case !
|
2025-10-16 12:43:32 +02:00
|
|
|
set argv not
|
2025-09-17 11:53:21 +02:00
|
|
|
case .
|
2025-10-16 12:43:32 +02:00
|
|
|
set argv source
|
2025-01-19 18:34:42 +01:00
|
|
|
case :
|
2025-10-16 12:43:32 +02:00
|
|
|
set argv true
|
2025-01-19 18:34:42 +01:00
|
|
|
case '['
|
2025-10-16 12:43:32 +02:00
|
|
|
set argv test
|
2025-01-19 18:34:42 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-15 23:46:22 -07:00
|
|
|
if not set -q argv[2] && status list-files "man/man1/$argv[1].1" &>/dev/null
|
2025-10-14 01:31:10 +02:00
|
|
|
set -l basename $argv[1].1
|
|
|
|
|
function __fish_man -V basename -a man1
|
|
|
|
|
command man $man1/$basename
|
|
|
|
|
end
|
|
|
|
|
__fish_data_with_directory man/man1 \
|
|
|
|
|
(string escape --style=regex -- $basename) __fish_man
|
|
|
|
|
__fish_with_status functions --erase __fish_man
|
|
|
|
|
else
|
|
|
|
|
command man $argv
|
2025-08-29 11:40:42 +02:00
|
|
|
end
|
2025-01-19 18:34:42 +01:00
|
|
|
end
|