diff --git a/share/completions/apropos.fish b/share/completions/apropos.fish index 0954dcd5e..0add195b9 100644 --- a/share/completions/apropos.fish +++ b/share/completions/apropos.fish @@ -1,11 +1,10 @@ function __fish_complete_apropos - if test (commandline -ct) - switch (commandline -ct) - case '-**' + set -f str (commandline -ct | string escape --style=regex) + switch "$str" + case '-**' - case '*' - apropos $str 2>/dev/null | string replace -rf -- "^(.*$str([^ ]*).*)" "$str\$2\t\$1" - end + case '*' + __fish_apropos "^$str" 2>/dev/null | string replace -rf -- '^([^(\s]+) ?\([,\w]+\)\s+-?\s?(.*)$' '$1\t$2' end end diff --git a/share/functions/__fish_apropos.fish b/share/functions/__fish_apropos.fish index 4035abec6..fcc5f9f9c 100644 --- a/share/functions/__fish_apropos.fish +++ b/share/functions/__fish_apropos.fish @@ -36,7 +36,7 @@ if test $status -eq 0 -a (count $sysver) -eq 3 set age (path mtime -R -- $whatis) end - MANPATH="$dir" apropos "^$argv" + MANPATH="$dir" apropos "$argv" if test $age -ge $max_age test -d "$dir" || mkdir -m 700 -p $dir @@ -46,6 +46,8 @@ if test $status -eq 0 -a (count $sysver) -eq 3 end else function __fish_apropos - apropos $argv + # we only ever prefix match for completions. This also ensures results for bare apropos + # (apropos '' gives no results, but apropos '^' lists all manpages) + apropos "$argv" end end diff --git a/share/functions/__fish_complete_man.fish b/share/functions/__fish_complete_man.fish index 5f19aa2f1..3debe8861 100644 --- a/share/functions/__fish_complete_man.fish +++ b/share/functions/__fish_complete_man.fish @@ -32,7 +32,7 @@ function __fish_complete_man if test -n "$token" # Do the actual search - __fish_apropos $token 2>/dev/null | awk ' + __fish_apropos ^$token 2>/dev/null | awk ' BEGIN { FS="[\t ]- "; OFS="\t"; } # BSD/Darwin /^[^( \t]+(, [^( \t]+)*\('$section'\)/ { @@ -55,7 +55,7 @@ function __fish_complete_man split($1, t, " "); sect = substr(t[3], 2, length(t[3]) - 2); print t[1], sect ": " $2; - } + } # Solaris 11 # Does not display descriptions # Solaris apropos outputs embedded backspace in descriptions diff --git a/share/functions/__fish_describe_command.fish b/share/functions/__fish_describe_command.fish index 40424eff4..89a8fee3d 100644 --- a/share/functions/__fish_describe_command.fish +++ b/share/functions/__fish_describe_command.fish @@ -12,7 +12,7 @@ end 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 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, ", "); for (name in names) if (names[name] ~ /^'"$argv_regex"'.* *\([18]\)/ ) {