shithub: choc

Download patch

ref: ad37a8ff334476f57a1d0ea55b5022bca5010fe8
parent: 8993063b126c65e572944ca487f5b980abfcf60d
author: Fabian Greffrath <fabian@greffrath.com>
date: Mon Oct 26 14:44:30 EDT 2015

Bash-Completion: First attempt at programatically creating the parameters list

--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,7 @@
 AC_OUTPUT([
 Makefile
 man/Makefile
+man/bash-completion/Makefile
 opl/Makefile
 opl/examples/Makefile
 pcsound/Makefile
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = bash-completion
+
 MANPAGE_GEN_FILES = environ.man           \
                     iwad_paths.man        \
                     doom.template         \
--- /dev/null
+++ b/man/bash-completion/Makefile.am
@@ -1,0 +1,42 @@
+BASH_COMPLETION_TEMPLATES = \
+    doom.template \
+    heretic.template \
+    hexen.template \
+    strife.template
+
+if HAVE_PYTHON
+
+BASH_COMPLETION_SCRIPTLETS = \
+    @PROGRAM_PREFIX@doom \
+    @PROGRAM_PREFIX@heretic \
+    @PROGRAM_PREFIX@hexen \
+    @PROGRAM_PREFIX@strife
+
+noinst_DATA = $(BASH_COMPLETION_SCRIPTLETS)
+CLEANFILES = $(BASH_COMPLETION_SCRIPTLETS)
+
+MANDIR = $(top_srcdir)/man
+DOCGEN = $(MANDIR)/docgen
+
+@PROGRAM_PREFIX@doom: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
+	$(DOCGEN) -g doom -b doom.template $(top_srcdir)/src $(top_srcdir)/src/doom > $@
+
+@PROGRAM_PREFIX@heretic: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
+	$(DOCGEN) -g heretic -b heretic.template $(top_srcdir)/src $(top_srcdir)/src/heretic > $@
+
+@PROGRAM_PREFIX@hexen: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
+	$(DOCGEN) -g hexen -b hexen.template $(top_srcdir)/src $(top_srcdir)/src/hexen > $@
+
+@PROGRAM_PREFIX@strife: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
+	$(DOCGEN) -g strife -b strife.template $(top_srcdir)/src $(top_srcdir)/src/strife > $@
+
+EXTRA_DIST = \
+    $(BASH_COMPLETION_TEMPLATES) \
+    $(BASH_COMPLETION_SCRIPTLETS)
+
+else
+
+EXTRA_DIST = \
+    $(BASH_COMPLETION_TEMPLATES)
+
+endif
--- a/man/bash-completion/chocolate-doom
+++ /dev/null
@@ -1,58 +1,0 @@
-# bash completion for Chocolate Doom                       -*- shell-script -*-
-
-_chocolate_doom()
-{
-    local cur prev words cword
-    _init_completion || return
-
-    case $prev in
-        -config|-extraconfig)
-            _filedir cfg
-            ;;
-        -episode)
-            COMPREPLY=(1 2 3 4)
-            ;;
-        -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
-            _filedir wad
-            ;;
-        -loadgame)
-            COMPREPLY=(0 1 2 3 4 5)
-            ;;
-        -pack)
-            COMPREPLY=(doom2 tnt plutonia)
-            ;;
-        -skill)
-            COMPREPLY=(1 2 3 4 5)
-            ;;
-        -gameversion)
-            COMPREPLY=(1.9 ultimate final final2 hacx chex)
-            ;;
-        -setmen)
-            COMPREPLY=(dos622 dos71 dosbox)
-            ;;
-        -playdemo|-timedemo)
-            _filedir lmp
-            ;;
-        -deh)
-            _filedir bex deh
-            ;;
-    esac
-
-    if [[ $cur == -* ]]; then
-        COMPREPLY=( $( compgen -W '-1 -2 -3 -aa -af -altdeath -as -autojoin -avg
-        -cdrom -config -connect -deathmatch -dedicated -deh -dehlump -devparm
-        -donut -dumpsubstconfig -dup -episode -extraconfig -extratics -fast
-        -file -fullscreen -gameversion -geometry -grabmouse -height
-        -ignoreversion -iwad -left -loadgame -localsearch -longtics -maxdemo -mb
-        -merge -mmap -newsync -noblit -nocheats -nodeh -nodes -nodraw
-        -nograbmouse -nomonsters -nomouse -nomusic -nonovert -nosfx -nosound
-        -novert -nwtmerge -pack -playdemo -port -privateserver -query -record
-        -respawn -right -search -server -servername -setmem -skill -solo
-        -spechit -statdump -timedemo -timer -turbo -warp -width -window
-        -zonescan -zonezero ' -- "$cur" ) )
-    fi
-} &&
-
-complete -F _chocolate_doom chocolate-doom chocolate-heretic chocolate-hexen chocolate-strife
-
-# ex: ts=4 sw=4 et filetype=sh
--- /dev/null
+++ b/man/bash-completion/doom.template
@@ -1,0 +1,39 @@
+# bash completion for Chocolate Doom                       -*- shell-script -*-
+
+_chocolate_doom()
+{
+    local cur prev words cword
+    _init_completion || return
+
+    case $prev in
+        -config|-extraconfig)
+            _filedir cfg
+            ;;
+        -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
+            _filedir wad
+            ;;
+        -pack)
+            COMPREPLY=(doom2 tnt plutonia)
+            ;;
+        -gameversion)
+            COMPREPLY=(1.9 ultimate final final2 hacx chex)
+            ;;
+        -setmen)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+        -playdemo|-timedemo)
+            _filedir lmp
+            ;;
+        -deh)
+            _filedir bex deh
+            ;;
+    esac
+
+    if [[ $cur == -* ]]; then
+        COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
+    fi
+} &&
+
+complete -F _chocolate_doom chocolate-doom
+
+# ex: ts=4 sw=4 et filetype=sh
--- /dev/null
+++ b/man/bash-completion/heretic.template
@@ -1,0 +1,36 @@
+# bash completion for Chocolate Heretic                    -*- shell-script -*-
+
+_chocolate_heretic()
+{
+    local cur prev words cword
+    _init_completion || return
+
+    case $prev in
+        -config|-extraconfig)
+            _filedir cfg
+            ;;
+        -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
+            _filedir wad
+            ;;
+        -hhever)
+            COMPREPLY=(1.0 1.2 1.3)
+            ;;
+        -setmen)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+        -playdemo|-timedemo)
+            _filedir lmp
+            ;;
+        -deh)
+            _filedir hhe
+            ;;
+    esac
+
+    if [[ $cur == -* ]]; then
+        COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
+    fi
+} &&
+
+complete -F _chocolate_heretic chocolate-heretic
+
+# ex: ts=4 sw=4 et filetype=sh
--- /dev/null
+++ b/man/bash-completion/hexen.template
@@ -1,0 +1,30 @@
+# bash completion for Chocolate Hexen                     -*- shell-script -*-
+
+_chocolate_hexen()
+{
+    local cur prev words cword
+    _init_completion || return
+
+    case $prev in
+        -config|-extraconfig)
+            _filedir cfg
+            ;;
+        -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
+            _filedir wad
+            ;;
+        -setmen)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+        -playdemo|-timedemo)
+            _filedir lmp
+            ;;
+    esac
+
+    if [[ $cur == -* ]]; then
+        COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
+    fi
+} &&
+
+complete -F _chocolate_hexen chocolate-hexen
+
+# ex: ts=4 sw=4 et filetype=sh
--- /dev/null
+++ b/man/bash-completion/strife.template
@@ -1,0 +1,36 @@
+# bash completion for Chocolate Strife                     -*- shell-script -*-
+
+_chocolate_strife()
+{
+    local cur prev words cword
+    _init_completion || return
+
+    case $prev in
+        -config|-extraconfig)
+            _filedir cfg
+            ;;
+        -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
+            _filedir wad
+            ;;
+        -gameversion)
+            COMPREPLY=(1.2 1.31)
+            ;;
+        -setmen)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+        -playdemo|-timedemo)
+            _filedir lmp
+            ;;
+        -deh)
+            _filedir seh
+            ;;
+    esac
+
+    if [[ $cur == -* ]]; then
+        COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
+    fi
+} &&
+
+complete -F _chocolate_strife chocolate-strife
+
+# ex: ts=4 sw=4 et filetype=sh
--- a/man/docgen
+++ b/man/docgen
@@ -106,6 +106,19 @@
 
         return result
 
+    def completion_output(self):
+        result = ""
+
+        self.params.sort()
+
+        for p in self.params:
+            if p.should_show():
+                result += p.completion_output(0)
+
+        result = result.rstrip()
+
+        return result
+
     def manpage_output(self):
         result = ".SH " + self.description.upper() + "\n"
 
@@ -278,6 +291,12 @@
 
         return result
 
+    def completion_output(self, w):
+
+        result = self.name + " "
+
+        return result
+
 # Read list of wiki pages
 
 def read_wikipages():
@@ -444,6 +463,15 @@
 
     print_template(template_file, content)
 
+def completion_output(targets, template_file):
+
+    content = ""
+
+    for t in targets:
+        content += t.completion_output() + "\n"
+
+    print_template(template_file, content)
+
 def usage():
     print("Usage: %s [-V] [-c tag] [-g game] ( -m | -w | -p ) <dir>..." \
             % sys.argv[0])
@@ -452,6 +480,7 @@
     print("   -m :  Manpage output")
     print("   -w :  Wikitext output")
     print("   -p :  Plaintext output")
+    print("   -b :  Bash-Completion output")
     print("   -V :  Don't show Vanilla Doom options")
     print("   -g :  Only document options for specified game.")
     sys.exit(0)
@@ -458,7 +487,7 @@
 
 # Parse command line
 
-opts, args = getopt.getopt(sys.argv[1:], "m:wp:c:g:V")
+opts, args = getopt.getopt(sys.argv[1:], "m:wp:b:c:g:V")
 
 output_function = None
 template = None
@@ -473,6 +502,9 @@
         output_function = wiki_output
     elif opt[0] == "-p":
         output_function = plaintext_output
+        template = opt[1]
+    elif opt[0] == "-b":
+        output_function = completion_output
         template = opt[1]
     elif opt[0] == "-V":
         show_vanilla_options = False