# bash completion for notmuch -*- shell-script -*- # # Copyright © 2013 Jani Nikula # # Based on the bash-completion package: # https://github.com/scop/bash-completion # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see https://www.gnu.org/licenses/ . # # Author: Jani Nikula # # # BUGS: # # Add space after an --option without parameter (e.g. reply --decrypt) # on completion. # _notmuch_shared_options="--help --uuid= --version" # $1: current input of the form prefix:partialinput, where prefix is # to or from. _notmuch_email() { local output prefix cur prefix="${1%%:*}" cur="${1#*:}" # Cut the input to be completed at punctuation because # (apparently) Xapian does not support the trailing wildcard '*' # operator for input with punctuation. We let compgen handle the # extra filtering required. cur="${cur%%[^a-zA-Z0-9]*}" case "$prefix" in # Note: It would be more accurate and less surprising to have # output=recipients here for to: addresses, but as gathering # the recipient addresses requires disk access for each # matching message, this becomes prohibitively slow. to|from) output=sender;; *) return;; esac # Only emit plain, lower case, unique addresses. notmuch address --output=$output $prefix:"${cur}*" | \ sed 's/[^<]*<\([^>]*\)>/\1/' | tr "[:upper:]" "[:lower:]" | sort -u } _notmuch_mimetype() { # use mime types from mime-support package if available, and fall # back to a handful of common ones otherwise if [ -r "/etc/mime.types" ]; then sed -n '/^[[:alpha:]]/{s/[[:space:]].*//;p;}' /etc/mime.types else cat </dev/null 2>&1 || return _init_completion || return COMPREPLY=() # subcommand _get_first_arg # complete --help option like the subcommand if [ -z "${arg}" -a "${prev}" = "--help" ]; then arg="help" fi if [ -z "${arg}" ]; then # top level completion case "${cur}" in -*) # XXX: handle ${_notmuch_shared_options} and --config= local options="--help --version" COMPREPLY=( $(compgen -W "${options}" -- ${cur}) ) ;; *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;; esac elif [ "${arg}" = "help" ]; then # handle help command specially due to _notmuch_commands usage local help_topics="$_notmuch_commands hooks search-terms properties" COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) ) else # complete using _notmuch_subcommand if one exist local completion_func="_notmuch_${arg//-/_}" declare -f $completion_func >/dev/null && $completion_func fi } && complete -F _notmuch notmuch