__fish_describe_command: print only exact match and exit

Mimic the behavior of Linux's `apropos -e` and ~BSD's `apropos -f` with
the awk script by disallowing trailing characters in the name of the
manpage as compared to the original input string. Apart from being
faster (by aborting earlier and stopping `apropos` by breaking the pipe
after the first match), it's also more correct.
This commit is contained in:
Mahmoud Al-Qudsi 2020-02-17 20:17:09 -06:00
parent 3c7019b335
commit 535845861a

View file

@ -32,10 +32,11 @@ function __fish_describe_command -d "Command used to find descriptions for comma
apropos $argv 2>/dev/null | awk -v FS=" +- +" '{
split($1, names, ", ");
for (name in names)
if (names[name] ~ /^'"$argv_regex"'.* *\([18]\)/ ) {
if (names[name] ~ /^'"$argv_regex"'[^A-z._-]* *\([18]\)/ ) {
sub( "( |\t)*\\\([18]\\\)", "", names[name] );
sub( " \\\[.*\\\]", "", names[name] );
print names[name] "\t" $2;
exit;
}
}'
end