aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_complete_man.fish
diff options
context:
space:
mode:
authorGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2013-11-27 17:58:43 +0800
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2013-11-27 17:58:43 +0800
commit0c4dab54f1544dff96c0e2d01f4c661e07f7fa49 (patch)
treeb3fa703a6c1346a4b02d580bef0b1595e30100fb /share/functions/__fish_complete_man.fish
parent84483b4aac7cfd5d59b5a1050f5d11a5f052af50 (diff)
__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.
Diffstat (limited to 'share/functions/__fish_complete_man.fish')
-rw-r--r--share/functions/__fish_complete_man.fish28
1 files changed, 27 insertions, 1 deletions
diff --git a/share/functions/__fish_complete_man.fish b/share/functions/__fish_complete_man.fish
index a5e4fa40..59c8c24e 100644
--- a/share/functions/__fish_complete_man.fish
+++ b/share/functions/__fish_complete_man.fish
@@ -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