[PATCH] completion: complete bash completion rewrite
authorJani Nikula <jani@nikula.org>
Sat, 2 Mar 2013 13:59:11 +0000 (15:59 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:49 +0000 (09:53 -0800)
f9/480e5e48d3b9fdff5eee272ee41d1e12d7edab [new file with mode: 0644]

diff --git a/f9/480e5e48d3b9fdff5eee272ee41d1e12d7edab b/f9/480e5e48d3b9fdff5eee272ee41d1e12d7edab
new file mode 100644 (file)
index 0000000..2ba7f7a
--- /dev/null
@@ -0,0 +1,442 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2974D431FBC\r
+       for <notmuch@notmuchmail.org>; Sat,  2 Mar 2013 05:59:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 3UMsi8Q2ZuoA for <notmuch@notmuchmail.org>;\r
+       Sat,  2 Mar 2013 05:59:22 -0800 (PST)\r
+Received: from mail-la0-f41.google.com (mail-la0-f41.google.com\r
+       [209.85.215.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 75071431FAE\r
+       for <notmuch@notmuchmail.org>; Sat,  2 Mar 2013 05:59:22 -0800 (PST)\r
+Received: by mail-la0-f41.google.com with SMTP id fo12so3799725lab.28\r
+       for <notmuch@notmuchmail.org>; Sat, 02 Mar 2013 05:59:18 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=x-received:from:to:cc:subject:date:message-id:x-mailer:mime-version\r
+       :content-type:content-transfer-encoding:x-gm-message-state;\r
+       bh=Io9UjuxI4w24YxTVti0DaJuMklkXppF3jick0RiU86M=;\r
+       b=aOsbfGZmFG2nST7QMpNjyXmJUahughCkBhU1iAPF55wAVJOsR+VjwtdAma/lNy4r9+\r
+       GCYTLGdLxpZDNUD+fx4fzW358WekZcXt6068qXiUzxrJkMo3/4umhH0OexMeKmy5iY2O\r
+       LTxv9udVe0bCwuMDkP7tDlyetp2851fjo9uvo7fgyN/oAwMlW5wkrNrNu9NEIRFpLGWk\r
+       eYpKdkUozP7D4exRVl78r7ixA5fKxY5nzMz7NZGf+NLi0NrQXA+24mO25W73DCr17PZy\r
+       zBOrxuOAAnQe28YdX20AjiilkvrUvZigQx0WaVnbE0EMWhmzV8bBP29LYaRdl4la2d4V\r
+       zODw==\r
+X-Received: by 10.152.123.34 with SMTP id lx2mr12213837lab.52.1362232757962;\r
+       Sat, 02 Mar 2013 05:59:17 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id k15sm5219143lbd.6.2013.03.02.05.59.15\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sat, 02 Mar 2013 05:59:16 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] completion: complete bash completion rewrite\r
+Date: Sat,  2 Mar 2013 15:59:11 +0200\r
+Message-Id: <1362232751-9571-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-Gm-Message-State:\r
+ ALoCoQnBWr2w6VgVpLhCorX1JRF5sLdjs1xTGVSB9TlCVLYY+aGhamiqXIZn8MzjhsCp0PjZCCN4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 02 Mar 2013 13:59:25 -0000\r
+\r
+Rewrite the bash completion script to actually do something\r
+useful. There are still a few rough edges (documented as BUGS/TODO),\r
+but it's already fairly good.\r
+\r
+In addition to completing all the notmuch keyword arguments, it does\r
+some nice stuff, like complete tags on 'notmuch tag (+|-)<TAB>' and\r
+config options on 'notmuch config (get|set) <TAB>'.\r
+\r
+This is all based on the bash-completion package [1], and will not\r
+work without it.\r
+\r
+[1] http://bash-completion.alioth.debian.org/\r
+\r
+---\r
+\r
+CAVEATS:\r
+\r
+This is pretty much "good enough" for me. The existing one was, IMHO,\r
+practically useless.\r
+\r
+There may be dependencies on the version of the bash-completion\r
+package. I do not know, and I don't have a huge interest in finding\r
+out. That way lay dragons.\r
+\r
+Regardless, I think this is a *huge* improvement on the status quo for\r
+anyone this works for. And if it doesn't, the loss is roughly\r
+equivalent to the usefulness of the old completion script, i.e. "not\r
+much". It's also a *much* more interesting starting point for anyone\r
+wishing to improve upon.\r
+---\r
+ completion/notmuch-completion.bash |  333 ++++++++++++++++++++++++++++--------\r
+ 1 file changed, 262 insertions(+), 71 deletions(-)\r
+ rewrite completion/notmuch-completion.bash (66%)\r
+\r
+diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
+dissimilarity index 66%\r
+index 8665268..cbd10aa 100644\r
+--- a/completion/notmuch-completion.bash\r
++++ b/completion/notmuch-completion.bash\r
+@@ -1,71 +1,262 @@\r
+-# Bash completion for notmuch\r
+-#\r
+-# Copyright © 2009 Carl Worth\r
+-#\r
+-# This program is free software: you can redistribute it and/or modify\r
+-# it under the terms of the GNU General Public License as published by\r
+-# the Free Software Foundation, either version 3 of the License, or\r
+-# (at your option) any later version.\r
+-#\r
+-# This program is distributed in the hope that it will be useful,\r
+-# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+-# GNU General Public License for more details.\r
+-#\r
+-# You should have received a copy of the GNU General Public License\r
+-# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
+-#\r
+-# Author: Carl Worth <cworth@cworth.org>\r
+-#\r
+-# Based on "notmuch help" as follows:\r
+-#\r
+-# Usage: notmuch <command> [args...]\r
+-#\r
+-# Where <command> and [args...] are as follows:\r
+-#\r
+-#     setup\r
+-#\r
+-#     new\r
+-#\r
+-#     search [options] <search-term> [...]\r
+-#\r
+-#     show <search-terms>\r
+-#\r
+-#     reply <search-terms>\r
+-#\r
+-#     tag +<tag>|-<tag> [...] [--] <search-terms> [...]\r
+-#\r
+-#     dump [<filename>]\r
+-#\r
+-#     restore <filename>\r
+-#\r
+-#     help [<command>]\r
+-\r
+-_notmuch()\r
+-{\r
+-    local current previous commands help_options\r
+-\r
+-    previous=${COMP_WORDS[COMP_CWORD-1]}\r
+-    current="${COMP_WORDS[COMP_CWORD]}"\r
+-\r
+-    commands="setup new search show reply tag dump restore help"\r
+-    help_options="setup new search show reply tag dump restore search-terms"\r
+-    search_options="--max-threads= --first= --sort="\r
+-\r
+-    COMPREPLY=()\r
+-\r
+-    case $COMP_CWORD in\r
+-        1)\r
+-            COMPREPLY=( $(compgen -W "${commands}" -- ${current}) ) ;;\r
+-        2)\r
+-            case $previous in\r
+-                help)\r
+-                    COMPREPLY=( $(compgen -W "${help_options}" -- ${current}) ) ;;\r
+-                search)\r
+-                    COMPREPLY=( $(compgen -W "${search_options}" -- ${current}) ) ;;\r
+-            esac\r
+-            ;;\r
+-    esac\r
+-}\r
+-\r
+-complete -o default -o bashdefault -F _notmuch notmuch\r
++# bash completion for notmuch                              -*- shell-script -*-\r
++#\r
++# Copyright © 2013 Jani Nikula\r
++#\r
++# Based on the bash-completion package:\r
++# http://bash-completion.alioth.debian.org/\r
++#\r
++# This program is free software: you can redistribute it and/or modify\r
++# it under the terms of the GNU General Public License as published by\r
++# the Free Software Foundation, either version 2 of the License, or\r
++# (at your option) any later version.\r
++#\r
++# This program is distributed in the hope that it will be useful,\r
++# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++# GNU General Public License for more details.\r
++#\r
++# You should have received a copy of the GNU General Public License\r
++# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++#\r
++# Author: Jani Nikula <jani@nikula.org>\r
++#\r
++#\r
++# BUGS/TODO:\r
++#\r
++# Add space after an --option without parameter (e.g. reply --decrypt)\r
++# on completion.\r
++#\r
++# Do not complete other options immediately after an --option= which\r
++# has no keyword value (e.g. reply --format-version=N).\r
++#\r
++# Filename completions for all file parameters (e.g. dump\r
++# --output=FILE or even config set database.path).\r
++#\r
++# Do not define _notmuch_commands at the top level.\r
++#\r
++# Consider completing options only if the string being completed\r
++# begins with '-' (i.e. do not offer option completions on\r
++# e.g. notmuch search <TAB>).\r
++#\r
++\r
++_notmuch_commands="config count dump help new reply restore search setup show tag"\r
++\r
++_notmuch_config()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion || return\r
++\r
++    case "${prev}" in\r
++      config)\r
++          COMPREPLY=( $(compgen -W "get set list" -- ${cur}) )\r
++          return\r
++          ;;\r
++      get|set)\r
++          COMPREPLY=( $(compgen -W "`notmuch config list | sed 's/=.*\$//'`" -- ${cur}) )\r
++          return\r
++          ;;\r
++    esac\r
++}\r
++\r
++_notmuch_count()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --output)\r
++          COMPREPLY=( $( compgen -W "messages threads" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --exclude)\r
++          COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    local options="--output= --exclude="\r
++    compopt -o nospace\r
++    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++}\r
++\r
++_notmuch_dump()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --format)\r
++          COMPREPLY=( $( compgen -W "sup batch-tag" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    local options="--format= --output="\r
++    compopt -o nospace\r
++    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++}\r
++\r
++_notmuch_help()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion || return\r
++\r
++    local help_topics="$_notmuch_commands hooks search-terms"\r
++    COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )\r
++}\r
++\r
++_notmuch_new()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion || return\r
++\r
++    local options="--no-hooks"\r
++    COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )\r
++}\r
++\r
++_notmuch_reply()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --format)\r
++          COMPREPLY=( $( compgen -W "default json sexp headers-only" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --reply-to)\r
++          COMPREPLY=( $( compgen -W "all sender" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    local options="--format= --format-version= --reply-to= --decrypt"\r
++    compopt -o nospace\r
++    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++}\r
++\r
++_notmuch_restore()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --format)\r
++          COMPREPLY=( $( compgen -W "sup batch-tag auto" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    local options="--format= --accumulate --input="\r
++    compopt -o nospace\r
++    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++}\r
++\r
++_notmuch_search()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --format)\r
++          COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --output)\r
++          COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --sort)\r
++          COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --exclude)\r
++          COMPREPLY=( $( compgen -W "true false flag" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    local options="--format= --output= --sort= --offset= --limit= --exclude="\r
++    compopt -o nospace\r
++    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++}\r
++\r
++# N/A\r
++# _notmuch_setup()\r
++# {\r
++# }\r
++\r
++_notmuch_show()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --entire-thread)\r
++          COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --format)\r
++          COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --exclude|--body)\r
++          COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt"\r
++    compopt -o nospace\r
++    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++}\r
++\r
++_notmuch_tag()\r
++{\r
++    local cur prev words cword split\r
++    # handle tags with colons and equal signs\r
++    _init_completion -n := || return\r
++\r
++    case "${cur}" in\r
++      +*) COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) );;\r
++      -*) COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) );;\r
++    esac\r
++    # handle tags with colons\r
++    __ltrim_colon_completions "${cur}"\r
++}\r
++\r
++_notmuch()\r
++{\r
++    local arg cur prev words cword split\r
++    _init_completion || return\r
++\r
++    COMPREPLY=()\r
++\r
++    # subcommand\r
++    _get_first_arg\r
++\r
++    # complete --help option like the subcommand\r
++    if [ -z "${arg}" -a "${prev}" = "--help" ]; then\r
++      arg="help"\r
++    fi\r
++\r
++    if [ -z "${arg}" ]; then\r
++      # top level completion\r
++      local top_options="--help --version"\r
++      case "${cur}" in\r
++          -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;;\r
++          *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;;\r
++      esac\r
++    else\r
++      # complete using _notmuch_subcommand if one exist\r
++      local completion_func="_notmuch_${arg//-/_}"\r
++      declare -f $completion_func >/dev/null && $completion_func\r
++    fi\r
++} &&\r
++complete -F _notmuch notmuch\r
+-- \r
+1.7.10.4\r
+\r