]> diplodocus.org Git - nmh/blobdiff - etc/bash_completion_nmh-gen
new.c: Order two return statements to match comment.
[nmh] / etc / bash_completion_nmh-gen
index 7451b2af0469d991dfd81cf4b7c85dc3e8166dff..ba5cf2ef87eb33a4c9e66a5ca5ed09fe604c3497 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#! /bin/sh
 #
 # Generates COMPLETION-BASH from man/mh-chart.man.
 #
 #
 # Generates COMPLETION-BASH from man/mh-chart.man.
 #
@@ -9,8 +9,8 @@
 mhchart=man/mh-chart.man
 
 #### Extract switches for nmh program.
 mhchart=man/mh-chart.man
 
 #### Extract switches for nmh program.
-switches() {
-    local program=$1
+prog_switches() {
+    program=$1
 
     #### Extract lines from just after .B program-name to just before
     #### blank line, and then only those that start with .RB, e.g.,
 
     #### Extract lines from just after .B program-name to just before
     #### blank line, and then only those that start with .RB, e.g.,
@@ -28,7 +28,7 @@ switches() {
 
 cat <<'EOF'
 # bash completions for nmh commands                        -*- shell-script -*-
 
 cat <<'EOF'
 # bash completions for nmh commands                        -*- shell-script -*-
-# This file was generated by COMPLETION-BASH-gen.
+# This file was generated by etc/bash_completion_nmh-gen.
 #
 # This code is Copyright (c) 2016, by the authors of nmh.
 # See the COPYRIGHT file in the root directory of the nmh
 #
 # This code is Copyright (c) 2016, by the authors of nmh.
 # See the COPYRIGHT file in the root directory of the nmh
@@ -40,6 +40,8 @@ _nmh() {
   local -a switches
 
   COMPREPLY=()
   local -a switches
 
   COMPREPLY=()
+  #### Complete filenames.
+  compopt -o default
 
   case ${COMP_WORDS[COMP_CWORD]} in
   -*) case $1 in
 
   case ${COMP_WORDS[COMP_CWORD]} in
   -*) case $1 in
@@ -51,7 +53,7 @@ EOF
 programs=`egrep '\.B [^\-]' "$mhchart" | \
           sed -e 's/^\.B //' -e 's/ .*//' -e 's|%[^%]*%/||' -e 's/\\-/-/'`
 for program in $programs; do
 programs=`egrep '\.B [^\-]' "$mhchart" | \
           sed -e 's/^\.B //' -e 's/ .*//' -e 's|%[^%]*%/||' -e 's/\\-/-/'`
 for program in $programs; do
-    switches=`switches "$program"`
+    switches=`prog_switches "$program"`
     # Support mime as alias for mhbuild.
     [ "$program" = mhbuild ]  &&  program='mhbuild|mime'
     printf '      %s) switches=(%s) ;;\n' "$program" "$switches"
     # Support mime as alias for mhbuild.
     [ "$program" = mhbuild ]  &&  program='mhbuild|mime'
     printf '      %s) switches=(%s) ;;\n' "$program" "$switches"
@@ -64,10 +66,12 @@ cat <<'EOF'
 
   +*) switches=($(folder -all -fast -recurse | sed 's/^/+/')) ;;
 
 
   +*) switches=($(folder -all -fast -recurse | sed 's/^/+/')) ;;
 
-  [flc.np]*) switches=(first last cur . next prev) ;;
+  #### Complete special message names, except after -file.  The compopt -o default above provides filename completions.  Assume that -file was fully completed, so don't need to match -fil, etc.
+  [flc.np]*) [ ${COMP_CWORD:-0} -lt 2  -o  ${COMP_WORDS[$(($COMP_CWORD - 1))]} != -file ]  &&
+                 switches=(first last cur . next prev) ;;
   esac
 
   esac
 
-  #### Special case.
+  #### Special case:  add "new" to mhpath's completions.
   [ $1 = mhpath ]  &&  switches=("${switches[*]}" + new)
 
   COMPREPLY=($(compgen -W "${switches[*]}" -- ${COMP_WORDS[COMP_CWORD]}))
   [ $1 = mhpath ]  &&  switches=("${switches[*]}" + new)
 
   COMPREPLY=($(compgen -W "${switches[*]}" -- ${COMP_WORDS[COMP_CWORD]}))