]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-completion.bash
bash-completion: Complete options for notmuch search
[notmuch] / notmuch-completion.bash
index b4335fdf31fc93cc54d62179220352d5020c27b6..8665268c789eda9b789849bf999d59f0a4f87aa3 100644 (file)
 
 _notmuch()
 {
-    current="$2"
+    local current previous commands help_options
 
-    commands="setup new search show reply tag dump restore help"
+    previous=${COMP_WORDS[COMP_CWORD-1]}
+    current="${COMP_WORDS[COMP_CWORD]}"
 
+    commands="setup new search show reply tag dump restore help"
     help_options="setup new search show reply tag dump restore search-terms"
+    search_options="--max-threads= --first= --sort="
 
     COMPREPLY=()
-    prev=${COMP_WORDS[COMP_CWORD-1]}
 
-    if [[ "$COMP_CWORD" == "1" ]]; then
-       COMPREPLY=( $(compgen -W "${commands}" -- ${current}) )
-    fi
-
-    if [[ $prev = "help" && "$COMP_CWORD" == "2" ]]; then
-       COMPREPLY=( $(compgen -W "${help_options}" -- ${current}) )
-    fi
+    case $COMP_CWORD in
+        1)
+            COMPREPLY=( $(compgen -W "${commands}" -- ${current}) ) ;;
+        2)
+            case $previous in
+                help)
+                    COMPREPLY=( $(compgen -W "${help_options}" -- ${current}) ) ;;
+                search)
+                    COMPREPLY=( $(compgen -W "${search_options}" -- ${current}) ) ;;
+            esac
+            ;;
+    esac
 }
+
 complete -o default -o bashdefault -F _notmuch notmuch