]>
diplodocus.org Git - nmh/blob - etc/bash_completion_nmh-gen
3 # Generates COMPLETION-BASH from man/mh-chart.man.
5 # This code is Copyright (c) 2016, by the authors of nmh.
6 # See the COPYRIGHT file in the root directory of the nmh
7 # distribution for complete copyright information.
9 mhchart
= man
/ mh
-chart .man
11 #### Extract switches for nmh program.
15 #### Extract lines from just after .B program-name to just before
16 #### blank line, and then only those that start with .RB, e.g.,
17 #### .RB [ \-list " | " \-nolist ]
18 #### .RB " | " \-autoheaderencoding ]
19 #### .RB [ \-\|\-component
20 awk '/^.B.*(\/| )' " $program " '/,/^$/ {
24 sed -e 's/\.RB //g' -e 's/\[//g' -e 's/\]//g' \
25 -e 's/\( \\ \)*//g' -e 's/-|-/-/g' -e 's/" *| "//g' \
26 -e 's/^ *//' -e 's/ *$//' -e 's/ */ /g'
30 # bash completions for nmh commands -*- shell-script -*-
31 # This file was generated by etc/bash_completion_nmh-gen.
33 # This code is Copyright (c) 2016, by the authors of nmh.
34 # See the COPYRIGHT file in the root directory of the nmh
35 # distribution for complete copyright information.
37 # To use: source at a bash prompt or in an initialization file.
43 #### Complete filenames.
46 case ${COMP_WORDS[COMP_CWORD]} in
50 #### Extract program names from lines such as:
51 #### .B %nmhlibexecdir%/install\-mh
52 #### .B new \-mode fnext
53 programs
= `egrep '\.B [^\-]' " $mhchart " | \
54 sed -e 's/^\.B //' -e 's/ .*//' -e 's|%[^%]*%/||' -e 's/ \\ -/-/'`
55 for program
in $programs ; do
56 switches
= `prog_switches " $program "`
57 # Support mime as alias for mhbuild.
58 [ " $program " = mhbuild
] && program
= 'mhbuild|mime'
59 printf ' %s) switches=(%s) ;; \n ' " $program " " $switches "
62 programs
= " $programs mime"
67 +*) switches=( $(folder -all -fast -recurse | sed 's/^/+/') ) ;;
69 #### 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.
70 [flc.np]*) [ ${COMP_CWORD:-0} -lt 2 -o ${COMP_WORDS[$(($COMP_CWORD - 1))]} != -file ] &&
71 switches=(first last cur . next prev) ;;
74 #### Special case: add "new" to mhpath's completions.
75 [ $1 = mhpath ] && switches=(" ${switches[*]} " + new)
77 COMPREPLY=( $(compgen -W "${switches[*]}" -- ${COMP_WORDS[COMP_CWORD]}) )
82 #### There better not be an nmh program name with whitespace in it.
83 echo complete
-F _nmh
$programs