mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
__fish_complete_man: Use awk to parse output of apropos
Closes #960. Uses pattern matching rather than OS detection. Works with BSD awk, GNU awk and Solaris' nawk.
This commit is contained in:
parent
84483b4aac
commit
0c4dab54f1
1 changed files with 27 additions and 1 deletions
|
@ -21,7 +21,33 @@ function __fish_complete_man
|
|||
set section $section"[^)]*"
|
||||
|
||||
# Do the actual search
|
||||
apropos (commandline -ct) ^/dev/null | sgrep \^(commandline -ct) | sed -n -e 's/\([^ ]*\).*(\('$section'\)) *- */\1'\t'\2: /p'
|
||||
apropos (commandline -ct) ^/dev/null | awk '
|
||||
BEGIN { FS="[\t ]- "; OFS="\t"; }
|
||||
# BSD/Darwin
|
||||
/^[^( \t]+\('$section'\)/ {
|
||||
split($1, pages, ", ");
|
||||
for (i in pages) {
|
||||
page = pages[i];
|
||||
sub(/[ \t]+/, "", page);
|
||||
paren = index(page, "(");
|
||||
name = substr(page, 1, paren - 1);
|
||||
sect = substr(page, paren + 1, length(page) - paren - 1);
|
||||
print name, sect ": " $2;
|
||||
}
|
||||
}
|
||||
# Linux
|
||||
/^[^( \t]+ \('$section'\)/ {
|
||||
split($1, t, " ");
|
||||
sect = substr(t[2], 2, length(t[2]) - 2);
|
||||
print t[1], sect ": " $2;
|
||||
}
|
||||
# Solaris
|
||||
/^[^( \t]+\t+[^\(\t]/ {
|
||||
split($1, t, " ");
|
||||
sect = substr(t[3], 2, length(t[3]) - 2);
|
||||
print t[2], sect ": " $2;
|
||||
}
|
||||
'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue