[PATCH v3] completion: complete mimetype: search prefix

Tomi Ollila tomi.ollila at iki.fi
Fri Nov 11 12:29:57 PST 2016


On Wed, Nov 02 2016, Jani Nikula <jani at nikula.org> wrote:

> Use /etc/mime.types if available, parsed using a sed one-liner, and
> fall back to a handful of common types otherwise.
>
> ---
>
> v2: smarter sed thanks to Lucas Hoffmann
>
> v3: use Tomi's sed... though I'm not sure what the improvement is...

LGTM.

The difference is that using '\t' is GNU sed extension -- other seds just
consider that being 't' -- Using [[:space:]] works also on macOS, *BSD...

> ---
>  completion/notmuch-completion.bash | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
> index 78047b5f424d..d44b2a2811f0 100644
> --- a/completion/notmuch-completion.bash
> +++ b/completion/notmuch-completion.bash
> @@ -58,6 +58,34 @@ _notmuch_email()
>  	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 <<EOF
> +application/gzip
> +application/msword
> +application/pdf
> +application/zip
> +audio/mpeg
> +audio/ogg
> +image/gif
> +image/jpeg
> +image/png
> +message/rfc822
> +text/calendar
> +text/html
> +text/plain
> +text/vcard
> +text/x-diff
> +text/x-vcalendar
> +EOF
> +    fi
> +}
> +
>  _notmuch_search_terms()
>  {
>      local cur prev words cword split
> @@ -85,6 +113,10 @@ _notmuch_search_terms()
>  	    COMPREPLY=( $(compgen -d "$path/${cur##folder:}" | \
>  		sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) )
>  	    ;;
> +	mimetype:*)
> +	    compopt -o nospace
> +	    COMPREPLY=( $(compgen -P "mimetype:" -W "`_notmuch_mimetype ${cur}`" -- ${cur##mimetype:}) )
> +	    ;;
>  	*)
>  	    local search_terms="from: to: subject: attachment: mimetype: tag: id: thread: folder: path: date: lastmod:"
>  	    compopt -o nospace
> -- 
> 2.1.4
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list