]> git.decadent.org.uk Git - ion3.git/blobdiff - utils/ion-completeman.in
Add 20080207-1.
[ion3.git] / utils / ion-completeman.in
index 9f71f83877d3b71000c46bec7dcef40d430f96c5..135efaf248dc5855e06103b22c66c3df98670c71 100644 (file)
@@ -1,11 +1,14 @@
 #!/bin/sh
 
+prog=$0
 tocompl=""
 section=""
 beg=""
 action=""
 usercache=""
 syscache=""
+linebeg="^"
+icase=""
 
 translate_grepsafe() { 
     # The regexp below is supposed to be [\[\].*$^\\], but sed sucks
@@ -15,30 +18,46 @@ translate_grepsafe() {
     sed 's:^[ \t]*\(.*\)[ \t]*$:\1:; s:[[.[.][.].].*$^\\]:\\&:g'
 }
 
-case "$1" in
-    -complete)
-        read section tocompl << EOF
+
+while test $# -ge 1; do
+    case "$1" in
+        -mid)
+            linebeg=""
+            ;;
+        -icase)
+            icase="-i"
+            ;;
+        -complete)
+            read section tocompl << EOF
 $2
 EOF
-        if test "$tocompl" = ""; then
-            tocompl="$section"
-            section=""
-        else
-            beg="$section "
-        fi
-        tocompl=`echo "$tocompl" | translate_grepsafe`
-        action="complete"
-        ;;
-    -mkusercache)
-        action="mkusercache"
-        ;;
-    -mksyscache)
-        action="mksyscache"
-        ;;
-esac
-   
+            if test "$tocompl" = ""; then
+                tocompl="$section"
+                section=""
+            else
+                beg="$section "
+            fi
+            tocompl=`echo "$tocompl" | translate_grepsafe`
+            action="complete"
+            break
+            ;;
+        -mkusercache)
+            action="mkusercache"
+            break
+            ;;
+        -mksyscache)
+            action="mksyscache"
+            break
+            ;;
+        *)
+            break
+            ;;
+    esac
+    shift
+done
+
 if test "x$action" = x; then
-    echo 2>&1 "Usage: $0 (-complete what|-mkusercache|-mksyscache)"
+    echo 2>&1 "Usage: $prog [-icase] [-mid] (-complete what|-mkusercache|-mksyscache)"
     exit 1
 fi
         
@@ -58,7 +77,7 @@ grepper() {
         if test "$section" = ""; then
             section="[0-9]"
         fi
-        grep "^$tocompl.*\.$section"
+        grep $icase "$linebeg$tocompl.*\.$section"
     fi
 }
 
@@ -88,15 +107,15 @@ if test "x$HOME" != x; then
     usercache="$HOME/.ion3/mancache"
 fi
 
-syscache="@VARDIR@/mancache"
+vardir=${ION_VAR_PATH-@VARDIR@}
+syscache="$vardir/mancache"
+
 
 case "$action" in
     complete)
         if test "x$usercache" != x -a -f "$usercache"; then
             cachefile="$usercache"
-        fi
-        
-        if test -f "$syscache"; then
+        elif test -f "$syscache"; then
             cachefile="$syscache"
         fi
         
@@ -117,7 +136,7 @@ case "$action" in
         fi
         ;;
     mksyscache)
-        mkdir -p "@VARDIR@"
+        mkdir -p "$vardir"
         scan > "$syscache"
         ;;
 esac