← Back to team overview

apport-hackers team mailing list archive

[Merge] lp:~yofel/apport/bash_completion_r1839_update into lp:apport

 

Philip Muškovac has proposed merging lp:~yofel/apport/bash_completion_r1839_update into lp:apport.

Requested reviews:
  Apport upstream developers (apport-hackers)

For more details, see:
https://code.launchpad.net/~yofel/apport/bash_completion_r1839_update/+merge/49733

With this the bash completion again complies with the available options and hides the private symptom scripts.
-- 
https://code.launchpad.net/~yofel/apport/bash_completion_r1839_update/+merge/49733
Your team Apport upstream developers is requested to review the proposed merge of lp:~yofel/apport/bash_completion_r1839_update into lp:apport.
=== modified file 'etc/bash_completion.d/apport_completion'
--- etc/bash_completion.d/apport_completion	2010-06-23 16:00:38 +0000
+++ etc/bash_completion.d/apport_completion	2011-02-14 23:36:07 +0000
@@ -9,7 +9,10 @@
     local syms
     if [ -r /usr/share/apport/symptoms ]; then 
         for FILE in $(ls /usr/share/apport/symptoms); do
-           syms="$syms ${FILE%.py}"
+            # hide utility files and symptoms that don't have a run() function
+            if [[ ! "$FILE" =~ ^_.* && -n $(egrep "^def run\s*\(.*\):" /usr/share/apport/symptoms/$FILE) ]]; then
+                syms="$syms ${FILE%.py}"
+            fi
         done
     fi
     echo $syms
@@ -46,8 +49,7 @@
 
 
     # available options
-    dashoptions='-h --help -f --file-bug -u --update-bug -s --symptom -p \
-                 --package -P --pid -c --crash-file --save -v --version'
+    dashoptions='-h --help --save -v --version --tag'
 
     case "$prev" in
     ubuntu-bug | apport-bug)
@@ -65,65 +67,35 @@
         esac
 
     ;;
-    -f | --file-bug)
-        param="-P --pid -p --package -s --symptom"
-        COMPREPLY=( $( compgen -W "$param $(_apport_symptoms)" -- $cur) )
-
-    ;;
-    -p | --package)
-        COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
-
-    ;;
-    -u | --update-bug)
-        param="-p --package"
-        COMPREPLY=( $( compgen -W "$param" -- $cur) )
-
-    ;;
-    -s | --symptom)
-        COMPREPLY=( $( compgen -W "$(_apport_symptoms)" -- $cur) )
-
-    ;;
-    -P | --pid)
-	COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) )
-
-    ;;
     --save)
         COMPREPLY=( $( compgen -o default -G "$cur*" ) )
     
     ;;
-    -c | --crash-file)
-        # only show *.apport *.crash files
-        COMPREPLY=( $( compgen -G "${cur}*.apport"
-                       compgen -G "${cur}*.crash" ) )
-
-    ;;
-    -h | --help | -v | --version)
+    -h | --help | -v | --version | --tag)
         # standalone parameters
         return 0
 
     ;;
     *)
-        if [ "${COMP_WORDS[COMP_CWORD-2]}" == "--save" ]; then
-            # use same completion as if no parameter is given
-            case "$cur" in
-            -*)
-                # parameter completion
-                COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
-
-            ;;
-            *)
-                _apport_parameterless 
-
-            ;;
-            esac
-
+        # --save is allowed only once, --tag multiple times
+        if [[ "${COMP_WORDS[*]}" =~ .*--save.* ]]; then
+            dashoptions='--tag'
         else
-            # save is allowed for most parameters
-            param="--save"
-            COMPREPLY=( $( compgen -W "$param" -- $cur) )
-
+            dashoptions='--save --tag'
         fi
 
+        case "$cur" in
+        -*)
+            # parameter completion
+            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
+
+        ;;
+        *)
+            _apport_parameterless 
+
+        ;;
+        esac
+
     ;;
     esac
 }
@@ -140,7 +112,7 @@
 
     # available options
     dashoptions='-h --help -f --file-bug -u --update-bug -s --symptom \
-                 -c --crash-file --save -v --version'
+                 -c --crash-file --save -v --version --tag'
 
     case "$prev" in
     apport-cli)
@@ -177,13 +149,19 @@
                        compgen -G "${cur}*.crash" ) )
 
     ;;
-    -h | --help | -v | --version)
+    -h | --help | -v | --version | --tag)
         # standalone parameters
         return 0
 
     ;;
     *)
-        if [ "${COMP_WORDS[COMP_CWORD-2]}" == "--save" ]; then
+        if [[ "${COMP_WORDS[COMP_CWORD-2]}" == "--save" || "${COMP_WORDS[COMP_CWORD-2]}" == "--tag" ]]; then
+            # save may only be used once
+            if [[ "${COMP_WORDS[*]}" =~ .*--save.* ]]; then
+                dashoptions='-h --help -f --file-bug -u --update-bug -s --symptom \
+                             -c --crash-file -v --version --tag'
+            fi
+
             # use same completion as if no parameter is given
             case "$cur" in
             -*)
@@ -198,8 +176,9 @@
             esac
 
         else
-            # save is allowed for most parameters
-            param="--save"
+            # --save is allowed for most parameters
+            # --tag is allowed multiple times
+            param="--save --tag"
             COMPREPLY=( $( compgen -W "$param" -- $cur) )
 
         fi
@@ -238,7 +217,7 @@
 
     case "$prev" in 
     apport-collect)
-            COMPREPLY=( $( compgen -W "-p --package" -- $cur) )
+        COMPREPLY=( $( compgen -W "-p --package --tag" -- $cur) )
 
     ;;
     -p | --package)
@@ -246,6 +225,19 @@
         COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
 
     ;;
+    --tag)
+        # standalone parameter
+        return 0
+    ;;
+    *)
+        # only complete -p/--package once
+        if [[ "${COMP_WORDS[*]}" =~ .*\ -p.* || "${COMP_WORDS[*]}" =~ .*--package.* ]]; then
+            COMPREPLY=( $( compgen -W "--tag" -- $cur) )
+        else
+            COMPREPLY=( $( compgen -W "-p --package --tag" -- $cur) )
+        fi
+        
+    ;;
     esac
 }
 
@@ -255,3 +247,5 @@
 complete -F _apport-cli -o filenames -o dirnames apport-cli
 complete -F _apport-unpack -o filenames -o dirnames apport-unpack
 complete -F _apport-collect apport-collect
+
+# vi: syntax=bash