[PATCH v2] completion: complete bash completion rewrite
authorJani Nikula <jani@nikula.org>
Sun, 3 Mar 2013 20:59:28 +0000 (22:59 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:53 +0000 (09:53 -0800)
14/66421604dbd68f676649dbb44f82791237a3c8 [new file with mode: 0644]

diff --git a/14/66421604dbd68f676649dbb44f82791237a3c8 b/14/66421604dbd68f676649dbb44f82791237a3c8
new file mode 100644 (file)
index 0000000..f808225
--- /dev/null
@@ -0,0 +1,529 @@
+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 0AC6C431FAF\r
+       for <notmuch@notmuchmail.org>; Sun,  3 Mar 2013 12:59:40 -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 pkjq2JgMz3G0 for <notmuch@notmuchmail.org>;\r
+       Sun,  3 Mar 2013 12:59:38 -0800 (PST)\r
+Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com\r
+       [209.85.217.170]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 59E01431FAE\r
+       for <notmuch@notmuchmail.org>; Sun,  3 Mar 2013 12:59:38 -0800 (PST)\r
+Received: by mail-lb0-f170.google.com with SMTP id ge1so3485101lbb.29\r
+       for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 12:59:36 -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:in-reply-to\r
+       :references:mime-version:content-type:content-transfer-encoding\r
+       :x-gm-message-state;\r
+       bh=Dl3ZSDg0d/O6nzFGYLdHp/xm1tlWBXnW48bI8TMvbFo=;\r
+       b=Xm6N8ghAvdgnT4vvokgkaKDR89CLc8b3GDHrkac8okK1OwwyC1eG1iuP5RAdW0g0GJ\r
+       1nfzEffknAsoatW3Kmqo7qzfieTUdfDsX6PaAeiy3xKYNHIpZmc75fRsRXuu36gPFocw\r
+       7YRq1sKwGJKhTCmHxY31HcEms4QzMD9Leh+PcpdgHRxtIkm2s8qfY3PqRfYn83P/KZq3\r
+       +A9mB/RHzFFKEm+wAwnM39+u9PGfLnLaxqztUU52h/bz5jnew5Ydk8fbDgcU4ntq/7LB\r
+       A8bLTEi5RjPqFPYeW2e8dBVj12RHq1zuISNxEhzdq63Am0V1IKaTCPq4hVivQwyiLjQ3\r
+       o/Ug==\r
+X-Received: by 10.152.105.17 with SMTP id gi17mr5850556lab.46.1362344376699;\r
+       Sun, 03 Mar 2013 12:59:36 -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 fz16sm10670977lab.5.2013.03.03.12.59.34\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 03 Mar 2013 12:59:35 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] completion: complete bash completion rewrite\r
+Date: Sun,  3 Mar 2013 22:59:28 +0200\r
+Message-Id: <1362344368-27623-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1362232751-9571-1-git-send-email-jani@nikula.org>\r
+References: <1362232751-9571-1-git-send-email-jani@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-Gm-Message-State:\r
+ ALoCoQlqwy4HiHu7i84ZgJ7R62329lFLIXjPihe/XF+yxSW86YNNBiv4S7VFDXLqbZtOf0vZ9WYt\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: Sun, 03 Mar 2013 20:59:40 -0000\r
+\r
+Rewrite the bash completion script to actually do something\r
+useful. Supported completions:\r
+\r
+* All the notmuch commands, command line arguments, and values for\r
+  keyword arguments.\r
+\r
+* Tags after + and - in 'notmuch tag'.\r
+\r
+* Config options in 'notmuch config', and some config option values.\r
+\r
+* Search prefixes in all commands that use search terms.\r
+\r
+* Tags after tag: prefix in search terms.\r
+\r
+* User's email addresses after from: and to: in search terms.\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
+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 |  412 +++++++++++++++++++++++++++++-------\r
+ 1 file changed, 341 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..7bd7745 100644\r
+--- a/completion/notmuch-completion.bash\r
++++ b/completion/notmuch-completion.bash\r
+@@ -1,71 +1,341 @@\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:\r
++#\r
++# Add space after an --option without parameter (e.g. reply --decrypt)\r
++# on completion.\r
++#\r
++\r
++_notmuch_user_emails()\r
++{\r
++    notmuch config get user.primary_email\r
++    notmuch config get user.other_email\r
++}\r
++\r
++_notmuch_search_terms()\r
++{\r
++    local cur prev words cword split\r
++    # handle search prefixes and tags with colons and equal signs\r
++    _init_completion -n := || return\r
++\r
++    case "${cur}" in\r
++      tag:*)\r
++          COMPREPLY=( $(compgen -P "tag:" -W "`notmuch search --output=tags \*`" -- ${cur##tag:}) )\r
++          ;;\r
++      to:*)\r
++          COMPREPLY=( $(compgen -P "to:" -W "`_notmuch_user_emails`" -- ${cur##to:}) )\r
++          ;;\r
++      from:*)\r
++          COMPREPLY=( $(compgen -P "from:" -W "`_notmuch_user_emails`" -- ${cur##from:}) )\r
++          ;;\r
++      *)\r
++          local search_terms="from: to: subject: attachment: tag: id: thread: folder: date:"\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) )\r
++          ;;\r
++    esac\r
++    # handle search prefixes and tags with colons\r
++    __ltrim_colon_completions "${cur}"\r
++}\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
++          ;;\r
++      get|set)\r
++          COMPREPLY=( $(compgen -W "`notmuch config list | sed 's/=.*\$//'`" -- ${cur}) )\r
++          ;;\r
++      # these will also complete on config get, but we don't care\r
++      database.path)\r
++          _filedir\r
++          ;;\r
++      maildir.synchronize_flags)\r
++          COMPREPLY=( $(compgen -W "true false" -- ${cur}) )\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
++    ! $split &&\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--output= --exclude="\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++          ;;\r
++      *)\r
++          _notmuch_search_terms\r
++          ;;\r
++    esac\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
++      --output)\r
++          _filedir\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    ! $split &&\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--format= --output="\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++          ;;\r
++      *)\r
++          _notmuch_search_terms\r
++          ;;\r
++    esac\r
++}\r
++\r
++_notmuch_new()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion || return\r
++\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--no-hooks"\r
++          COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )\r
++          ;;\r
++    esac\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
++    ! $split &&\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--format= --format-version= --reply-to= --decrypt"\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++          ;;\r
++      *)\r
++          _notmuch_search_terms\r
++          ;;\r
++    esac\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
++      --input)\r
++          _filedir\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    ! $split &&\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--format= --accumulate --input="\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++          ;;\r
++    esac\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
++    ! $split &&\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--format= --output= --sort= --offset= --limit= --exclude="\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++          ;;\r
++      *)\r
++          _notmuch_search_terms\r
++          ;;\r
++    esac\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
++    ! $split &&\r
++    case "${cur}" in\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_search_terms\r
++          ;;\r
++    esac\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
++      +*)\r
++          COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )\r
++          ;;\r
++      -*)\r
++          COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )\r
++          ;;\r
++      *)\r
++          _notmuch_search_terms\r
++          return\r
++          ;;\r
++    esac\r
++    # handle tags with colons\r
++    __ltrim_colon_completions "${cur}"\r
++}\r
++\r
++_notmuch()\r
++{\r
++    local _notmuch_commands="config count dump help new reply restore search setup show tag"\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
++    elif [ "${arg}" = "help" ]; then\r
++      # handle help command specially due to _notmuch_commands usage\r
++      local help_topics="$_notmuch_commands hooks search-terms"\r
++      COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )\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