#!/bin/sh # # Generates COMPLETION-BASH from man/mh-chart.man. # # This code is Copyright (c) 2016, by the authors of nmh. # See the COPYRIGHT file in the root directory of the nmh # distribution for complete copyright information. mhchart=man/mh-chart.man #### Extract switches for nmh program. 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., #### .RB [ \-list " | " \-nolist ] #### .RB " | " \-autoheaderencoding ] #### .RB [ \-\|\-component awk '/^.B.*(\/| )'"$program"'/,/^$/ { if (/^\.RB /) print }' "$mhchart" | \ tr -d '\n' | \ sed -e 's/\.RB //g' -e 's/\[//g' -e 's/\]//g' \ -e 's/\(\\\)*//g' -e 's/-|-/-/g' -e 's/" *| "//g' \ -e 's/^ *//' -e 's/ *$//' -e 's/ */ /g' } cat <<'EOF' # bash completions for nmh commands -*- shell-script -*- # This file was generated by COMPLETION-BASH-gen. # # This code is Copyright (c) 2016, by the authors of nmh. # See the COPYRIGHT file in the root directory of the nmh # distribution for complete copyright information. # # To use: source at a bash prompt or in an initialization file. _nmh() { local -a switches COMPREPLY=() case ${COMP_WORDS[COMP_CWORD]} in -*) case $1 in EOF #### Extract program names from lines such as: #### .B %nmhlibexecdir%/install\-mh #### .B new \-mode fnext programs=`egrep '\.B [^\-]' "$mhchart" | \ sed -e 's/^\.B //' -e 's/ .*//' -e 's|%[^%]*%/||' -e 's/\\-/-/'` for program in $programs; do switches=`prog_switches "$program"` # Support mime as alias for mhbuild. [ "$program" = mhbuild ] && program='mhbuild|mime' printf ' %s) switches=(%s) ;;\n' "$program" "$switches" done programs="$programs mime" cat <<'EOF' esac ;; +*) switches=($(folder -all -fast -recurse | sed 's/^/+/')) ;; [flc.np]*) switches=(first last cur . next prev) ;; esac #### Special case. [ $1 = mhpath ] && switches=("${switches[*]}" + new) COMPREPLY=($(compgen -W "${switches[*]}" -- ${COMP_WORDS[COMP_CWORD]})) } EOF #### There better not be an nmh program name with whitespace in it. echo complete -F _nmh $programs