Fix apropos completions

The 'str' variable was apparently mistakenly removed by 49c5f96470.

Re-add it, and regex-escape it as well.

Allow completing on apropos <TAB> instaed of requiring an initial char.

Use __fish_apropos instead of apropos.

New regex to hopefully work on more platforms.

Explicitly use ^ instead of adding it at __fish_apropos
This commit is contained in:
Aaron Gyes 2022-10-28 09:39:43 -07:00
parent 054d0ac0ea
commit c887e5dbde
4 changed files with 12 additions and 11 deletions

View File

@ -1,11 +1,10 @@
function __fish_complete_apropos function __fish_complete_apropos
if test (commandline -ct) set -f str (commandline -ct | string escape --style=regex)
switch (commandline -ct) switch "$str"
case '-**' case '-**'
case '*' case '*'
apropos $str 2>/dev/null | string replace -rf -- "^(.*$str([^ ]*).*)" "$str\$2\t\$1" __fish_apropos "^$str" 2>/dev/null | string replace -rf -- '^([^(\s]+) ?\([,\w]+\)\s+-?\s?(.*)$' '$1\t$2'
end
end end
end end

View File

@ -36,7 +36,7 @@ if test $status -eq 0 -a (count $sysver) -eq 3
set age (path mtime -R -- $whatis) set age (path mtime -R -- $whatis)
end end
MANPATH="$dir" apropos "^$argv" MANPATH="$dir" apropos "$argv"
if test $age -ge $max_age if test $age -ge $max_age
test -d "$dir" || mkdir -m 700 -p $dir test -d "$dir" || mkdir -m 700 -p $dir
@ -46,6 +46,8 @@ if test $status -eq 0 -a (count $sysver) -eq 3
end end
else else
function __fish_apropos function __fish_apropos
apropos $argv # we only ever prefix match for completions. This also ensures results for bare apropos <TAB>
# (apropos '' gives no results, but apropos '^' lists all manpages)
apropos "$argv"
end end
end end

View File

@ -32,7 +32,7 @@ function __fish_complete_man
if test -n "$token" if test -n "$token"
# Do the actual search # Do the actual search
__fish_apropos $token 2>/dev/null | awk ' __fish_apropos ^$token 2>/dev/null | awk '
BEGIN { FS="[\t ]- "; OFS="\t"; } BEGIN { FS="[\t ]- "; OFS="\t"; }
# BSD/Darwin # BSD/Darwin
/^[^( \t]+(, [^( \t]+)*\('$section'\)/ { /^[^( \t]+(, [^( \t]+)*\('$section'\)/ {
@ -55,7 +55,7 @@ function __fish_complete_man
split($1, t, " "); split($1, t, " ");
sect = substr(t[3], 2, length(t[3]) - 2); sect = substr(t[3], 2, length(t[3]) - 2);
print t[1], sect ": " $2; print t[1], sect ": " $2;
} }
# Solaris 11 # Solaris 11
# Does not display descriptions # Does not display descriptions
# Solaris apropos outputs embedded backspace in descriptions # Solaris apropos outputs embedded backspace in descriptions

View File

@ -12,7 +12,7 @@ end
function __fish_describe_command -d "Command used to find descriptions for commands" function __fish_describe_command -d "Command used to find descriptions for commands"
# $argv will be inserted directly into the awk regex, so it must be escaped # $argv will be inserted directly into the awk regex, so it must be escaped
set -l argv_regex (string escape --style=regex -- "$argv") set -l argv_regex (string escape --style=regex -- "$argv")
__fish_apropos $argv 2>/dev/null | awk -v FS=" +- +" '{ __fish_apropos ^$argv 2>/dev/null | awk -v FS=" +- +" '{
split($1, names, ", "); split($1, names, ", ");
for (name in names) for (name in names)
if (names[name] ~ /^'"$argv_regex"'.* *\([18]\)/ ) { if (names[name] ~ /^'"$argv_regex"'.* *\([18]\)/ ) {