2020-01-31 21:55:08 +00:00
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function __fish_complete_man
|
2016-11-28 05:27:22 +00:00
|
|
|
# Try to guess what section to search in. If we don't know, we
|
2017-03-19 04:55:02 +00:00
|
|
|
# use [^)]*, which should match any section.
|
|
|
|
set -l section ""
|
|
|
|
set -l token (commandline -ct)
|
2024-01-22 06:42:45 +00:00
|
|
|
set -l prev (commandline -pxc)
|
2016-11-28 05:27:22 +00:00
|
|
|
set -e prev[1]
|
|
|
|
while set -q prev[1]
|
|
|
|
switch $prev[1]
|
|
|
|
case '-**'
|
2010-09-18 02:18:26 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
case '*'
|
2019-01-22 00:12:57 +00:00
|
|
|
set section (string escape --style=regex $prev[1])
|
|
|
|
set section (string replace --all / \\/ $section)
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
|
|
|
set -e prev[1]
|
|
|
|
end
|
2016-05-29 12:31:12 +00:00
|
|
|
|
2018-03-03 13:26:20 +00:00
|
|
|
set -l exclude_fish_commands
|
|
|
|
# Only include fish commands when section is empty or 1
|
2020-03-09 18:36:12 +00:00
|
|
|
if test -z "$section" -o "$section" = 1
|
2019-05-05 10:09:25 +00:00
|
|
|
set -e exclude_fish_commands
|
2018-03-03 13:26:20 +00:00
|
|
|
end
|
|
|
|
|
2016-05-29 12:31:12 +00:00
|
|
|
set section $section"[^)]*"
|
|
|
|
# If we don't have a token but a section, list all pages for that section.
|
|
|
|
# Don't do it for all sections because that would be overwhelming.
|
|
|
|
if test -z "$token" -a "$section" != "[^)]*"
|
|
|
|
set token "."
|
|
|
|
end
|
2006-02-15 02:22:28 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
if test -n "$token"
|
|
|
|
# Do the actual search
|
2022-10-28 16:39:43 +00:00
|
|
|
__fish_apropos ^$token 2>/dev/null | awk '
|
2017-01-27 04:00:43 +00:00
|
|
|
BEGIN { FS="[\t ]- "; OFS="\t"; }
|
|
|
|
# BSD/Darwin
|
2021-09-19 15:18:57 +00:00
|
|
|
/^[^( \t]+(, [^( \t]+)*\('$section'\)/ {
|
|
|
|
paren = index($1, "(");
|
|
|
|
sect = substr($1, paren + 1, length($1) - paren - 1);
|
|
|
|
aliases = substr($1, 1, paren - 1)
|
|
|
|
split(aliases, pages, ", ");
|
2017-01-27 04:00:43 +00:00
|
|
|
for (i in pages) {
|
2021-09-19 15:18:57 +00:00
|
|
|
print pages[i], sect ": " $2
|
2017-01-27 04:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
# man-db
|
|
|
|
/^[^( \t]+ +\('$section'\)/ {
|
|
|
|
split($1, t, " ");
|
|
|
|
sect = substr(t[2], 2, length(t[2]) - 2);
|
|
|
|
print t[1], sect ": " $2;
|
|
|
|
}
|
|
|
|
# man-db RHEL 5 with [aliases]
|
|
|
|
/^[^( \t]+ +\[.*\] +\('$section'\)/ {
|
|
|
|
split($1, t, " ");
|
|
|
|
sect = substr(t[3], 2, length(t[3]) - 2);
|
|
|
|
print t[1], sect ": " $2;
|
2022-10-28 16:39:43 +00:00
|
|
|
}
|
2017-01-27 04:00:43 +00:00
|
|
|
# Solaris 11
|
|
|
|
# Does not display descriptions
|
|
|
|
# Solaris apropos outputs embedded backspace in descriptions
|
|
|
|
/^[0-9]+\. [^( \t]*\('$section'\) / {
|
|
|
|
split($1, t, " ")
|
|
|
|
paren = index(t[2], "(");
|
|
|
|
name = substr(t[2], 1, paren - 1);
|
|
|
|
sect = substr(t[2], paren + 1, length(t[2]) - paren - 1);
|
|
|
|
print name, sect
|
|
|
|
}
|
|
|
|
'
|
|
|
|
|
2017-01-25 14:34:59 +00:00
|
|
|
# Fish commands are not given by apropos
|
2018-03-03 13:26:20 +00:00
|
|
|
if not set -ql exclude_fish_commands
|
2019-05-05 10:09:25 +00:00
|
|
|
set -l files $__fish_data_dir/man/man1/*.1
|
|
|
|
string replace -r '.*/([^/]+)\.1$' '$1\t1: fish command' -- $files
|
2018-03-03 13:26:20 +00:00
|
|
|
end
|
2016-05-29 12:31:12 +00:00
|
|
|
else
|
|
|
|
return 1
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
2016-05-29 12:31:12 +00:00
|
|
|
return 0
|
2006-02-15 02:22:28 +00:00
|
|
|
end
|