foxygit / doom Log in
commit cb4848b8daf84077e6b770900353389838a5a9a3
Author:     Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Fri Oct 30 08:53:37 2015 +0100
Commit:     Fabian Greffrath <fabian@greffrath.com>
CommitDate: Fri Oct 30 08:53:37 2015 +0100

    bash-completion: allow multiple files with the same extensions

    passed to the same switch, e.g. -file a.wad b.wad.

    Also, fix the -setmen typo.
---
 man/bash-completion/doom.template    | 28 ++++++++++++++++++++--------
 man/bash-completion/heretic.template | 26 +++++++++++++++++++-------
 man/bash-completion/hexen.template   | 20 ++++++++++++++++----
 man/bash-completion/strife.template  | 26 +++++++++++++++++++-------
 4 files changed, 74 insertions(+), 26 deletions(-)

diff --git a/man/bash-completion/doom.template b/man/bash-completion/doom.template
index d46fb8d4..535ad2a0 100644
--- a/man/bash-completion/doom.template
+++ b/man/bash-completion/doom.template
@@ -5,28 +5,40 @@ _chocolate_doom()
     local cur prev words cword
     _init_completion || return

-    case $prev in
+    # Save the previous switch on the command line in the prevsw variable
+    local i prevsw=""
+    for (( i=1; $cword > 1 && i <= $cword; i++ )); do
+        if [[ ${words[i]} == -* ]]; then
+            prevsw=${words[i]}
+        fi
+    done
+
+    # Allow adding more than one file with the same extension to the same switch
+    case $prevsw in
         -config|-extraconfig)
             _filedir cfg
             ;;
         -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
             _filedir wad
             ;;
+        -playdemo|-timedemo)
+            _filedir lmp
+            ;;
+        -deh)
+            _filedir '@(bex|deh)'
+            ;;
+    esac
+
+    case $prev in
         -pack)
             COMPREPLY=(doom2 tnt plutonia)
             ;;
         -gameversion)
             COMPREPLY=(1.9 ultimate final final2 hacx chex)
             ;;
-        -setmen)
+        -setmem)
             COMPREPLY=(dos622 dos71 dosbox)
             ;;
-        -playdemo|-timedemo)
-            _filedir lmp
-            ;;
-        -deh)
-            _filedir '@(bex|deh)'
-            ;;
     esac

     if [[ $cur == -* ]]; then
diff --git a/man/bash-completion/heretic.template b/man/bash-completion/heretic.template
index 84ea865c..5d658d46 100644
--- a/man/bash-completion/heretic.template
+++ b/man/bash-completion/heretic.template
@@ -5,19 +5,22 @@ _chocolate_heretic()
     local cur prev words cword
     _init_completion || return

-    case $prev in
+    # Save the previous switch on the command line in the prevsw variable
+    local i prevsw=""
+    for (( i=1; $cword > 1 && i <= $cword; i++ )); do
+        if [[ ${words[i]} == -* ]]; then
+            prevsw=${words[i]}
+        fi
+    done
+
+    # Allow adding more than one file with the same extension to the same switch
+    case $prevsw 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
             ;;
@@ -26,6 +29,15 @@ _chocolate_heretic()
             ;;
     esac

+    case $prev in
+        -hhever)
+            COMPREPLY=(1.0 1.2 1.3)
+            ;;
+        -setmem)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+    esac
+
     if [[ $cur == -* ]]; then
         COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
     fi
diff --git a/man/bash-completion/hexen.template b/man/bash-completion/hexen.template
index 0b75a639..b7e75f7f 100644
--- a/man/bash-completion/hexen.template
+++ b/man/bash-completion/hexen.template
@@ -5,21 +5,33 @@ _chocolate_hexen()
     local cur prev words cword
     _init_completion || return

-    case $prev in
+    # Save the previous switch on the command line in the prevsw variable
+    local i prevsw=""
+    for (( i=1; $cword > 1 && i <= $cword; i++ )); do
+        if [[ ${words[i]} == -* ]]; then
+            prevsw=${words[i]}
+        fi
+    done
+
+    # Allow adding more than one file with the same extension to the same switch
+    case $prevsw in
         -config|-extraconfig)
             _filedir cfg
             ;;
         -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
             _filedir wad
             ;;
-        -setmen)
-            COMPREPLY=(dos622 dos71 dosbox)
-            ;;
         -playdemo|-timedemo)
             _filedir lmp
             ;;
     esac

+    case $prev in
+        -setmem)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+    esac
+
     if [[ $cur == -* ]]; then
         COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
     fi
diff --git a/man/bash-completion/strife.template b/man/bash-completion/strife.template
index c5f73758..13c8a8ce 100644
--- a/man/bash-completion/strife.template
+++ b/man/bash-completion/strife.template
@@ -5,19 +5,22 @@ _chocolate_strife()
     local cur prev words cword
     _init_completion || return

-    case $prev in
+    # Save the previous switch on the command line in the prevsw variable
+    local i prevsw=""
+    for (( i=1; $cword > 1 && i <= $cword; i++ )); do
+        if [[ ${words[i]} == -* ]]; then
+            prevsw=${words[i]}
+        fi
+    done
+
+    # Allow adding more than one file with the same extension to the same switch
+    case $prevsw 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
             ;;
@@ -26,6 +29,15 @@ _chocolate_strife()
             ;;
     esac

+    case $prev in
+        -gameversion)
+            COMPREPLY=(1.2 1.31)
+            ;;
+        -setmem)
+            COMPREPLY=(dos622 dos71 dosbox)
+            ;;
+    esac
+
     if [[ $cur == -* ]]; then
         COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
     fi