* [PATCH] completion: complete mimetype: search prefix
@ 2016-10-22 18:55 Jani Nikula
2016-10-23 18:39 ` [PATCH v2] " Jani Nikula
0 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2016-10-22 18:55 UTC (permalink / raw)
To: notmuch
Use /etc/mime.types if available, with a homebrew sed parser, and fall
back to a handful of common types otherwise.
---
completion/notmuch-completion.bash | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
index 78047b5f424d..c75eb483a9f3 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 -e '/^[ \t]*\(#.*\)\?$/d;s/^\([^ \t]\+\).*$/\1/' < /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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2] completion: complete mimetype: search prefix
2016-10-22 18:55 [PATCH] completion: complete mimetype: search prefix Jani Nikula
@ 2016-10-23 18:39 ` Jani Nikula
2016-10-25 14:55 ` Tomi Ollila
0 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2016-10-23 18:39 UTC (permalink / raw)
To: notmuch
Use /etc/mime.types if available, with a homebrew sed parser, and fall
back to a handful of common types otherwise.
---
v2: smarter sed thanks to Lucas Hoffmann
---
completion/notmuch-completion.bash | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
index 78047b5f424d..e7e7d68b04ed 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 '/^[^ \t#]/{s/[ \t].*//;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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] completion: complete mimetype: search prefix
2016-10-23 18:39 ` [PATCH v2] " Jani Nikula
@ 2016-10-25 14:55 ` Tomi Ollila
2016-10-30 9:52 ` Jani Nikula
0 siblings, 1 reply; 8+ messages in thread
From: Tomi Ollila @ 2016-10-25 14:55 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> Use /etc/mime.types if available, with a homebrew sed parser, and fall
> back to a handful of common types otherwise.
I'd suggest the following line:
sed -n '/^[[:alpha:]]/ s/[[:space:]].*//p' /etc/mime.types
I tested the sed expression works on Linux and Darwin (macOS sierra).
I'd guess that any future 'ietf-token' starts with alpha character, and
'x-token' always starts with 'x'.
I agree with Jani that we'd rather used some other solution but so far
using sed(1) looks like best tolerable choice there is.
Tomi
PS: used something like the following to start the emacs to send this email:
#!/bin/sh
:; exec "${EMACS:-emacs}" --debug-init --load "$0" "$@"; exit
(eval-after-load "notmuch"
(lambda ()
(setq notmuch-command (concat (file-name-directory load-file-name)
"my-notmuch-remote-command"))
(setq smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 465
smtpmail-stream-type 'tls
smtpmail-debug-info t
smtpmail-debug-verb t
message-send-mail-function 'message-smtpmail-send-it)
))
(notmuch)
;; Local Variables:
;; mode: emacs-lisp
;; End:
PPS: first send failed, had to visit
https://www.google.com/settings/security/lesssecureapps
... it would be nice to know what makes this "less secure" application ...
> completion/notmuch-completion.bash | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
> index 78047b5f424d..e7e7d68b04ed 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 '/^[^ \t#]/{s/[ \t].*//;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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] completion: complete mimetype: search prefix
2016-10-25 14:55 ` Tomi Ollila
@ 2016-10-30 9:52 ` Jani Nikula
2016-10-30 20:53 ` Tomi Ollila
0 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2016-10-30 9:52 UTC (permalink / raw)
To: Tomi Ollila, notmuch
On Tue, 25 Oct 2016, Tomi Ollila <domo141@gmail.com> wrote:
> Jani Nikula <jani@nikula.org> writes:
>
>> Use /etc/mime.types if available, with a homebrew sed parser, and fall
>> back to a handful of common types otherwise.
>
> I'd suggest the following line:
>
> sed -n '/^[[:alpha:]]/ s/[[:space:]].*//p' /etc/mime.types
>
> I tested the sed expression works on Linux and Darwin (macOS sierra).
$ sed --version
sed (GNU sed) 4.2.2
$ sed -n '/^[[:alpha:]]/ s/[[:space:]].*//p' /etc/mime.types | wc -l
411
$ sed -n '/^[^ \t#]/{s/[ \t].*//;p;}' < /etc/mime.types | wc -l
787
BR,
Jani.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] completion: complete mimetype: search prefix
2016-10-30 9:52 ` Jani Nikula
@ 2016-10-30 20:53 ` Tomi Ollila
2016-11-02 18:46 ` [PATCH v3] " Jani Nikula
0 siblings, 1 reply; 8+ messages in thread
From: Tomi Ollila @ 2016-10-30 20:53 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> On Tue, 25 Oct 2016, Tomi Ollila <domo141@gmail.com> wrote:
>> Jani Nikula <jani@nikula.org> writes:
>>
>>> Use /etc/mime.types if available, with a homebrew sed parser, and fall
>>> back to a handful of common types otherwise.
>>
>> I'd suggest the following line:
>>
>> sed -n '/^[[:alpha:]]/ s/[[:space:]].*//p' /etc/mime.types
>>
>> I tested the sed expression works on Linux and Darwin (macOS sierra).
>
> $ sed --version
> sed (GNU sed) 4.2.2
>
> $ sed -n '/^[[:alpha:]]/ s/[[:space:]].*//p' /etc/mime.types | wc -l
> 411
>
> $ sed -n '/^[^ \t#]/{s/[ \t].*//;p;}' < /etc/mime.types | wc -l
> 787
Yes, I failed to notice that lines which did not have any space were
dropped from the output -- and Lucas Hoffmann's version handles that
case neatly (tried some alternatives, none so good (unless 's/\>.*//p')).
sed -n '/^[[:alpha:]]/{s/[[:space:]].*//;p;}' /etc/mime.types
Now I get the same m5sums from the output of latest 2 in this message,
so now it is more properly tested (sorry about that :)
Tomi
>
> BR,
> Jani.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] completion: complete mimetype: search prefix
2016-10-30 20:53 ` Tomi Ollila
@ 2016-11-02 18:46 ` Jani Nikula
2016-11-11 20:29 ` Tomi Ollila
2016-11-12 11:43 ` David Bremner
0 siblings, 2 replies; 8+ messages in thread
From: Jani Nikula @ 2016-11-02 18:46 UTC (permalink / raw)
To: Tomi Ollila, Jani Nikula, notmuch
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...
---
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] completion: complete mimetype: search prefix
2016-11-02 18:46 ` [PATCH v3] " Jani Nikula
@ 2016-11-11 20:29 ` Tomi Ollila
2016-11-12 11:43 ` David Bremner
1 sibling, 0 replies; 8+ messages in thread
From: Tomi Ollila @ 2016-11-11 20:29 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Wed, Nov 02 2016, Jani Nikula <jani@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@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] completion: complete mimetype: search prefix
2016-11-02 18:46 ` [PATCH v3] " Jani Nikula
2016-11-11 20:29 ` Tomi Ollila
@ 2016-11-12 11:43 ` David Bremner
1 sibling, 0 replies; 8+ messages in thread
From: David Bremner @ 2016-11-12 11:43 UTC (permalink / raw)
To: Jani Nikula, Tomi Ollila, Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> Use /etc/mime.types if available, parsed using a sed one-liner, and
> fall back to a handful of common types otherwise.
>
> ---
pushed to master
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-11-12 11:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-22 18:55 [PATCH] completion: complete mimetype: search prefix Jani Nikula
2016-10-23 18:39 ` [PATCH v2] " Jani Nikula
2016-10-25 14:55 ` Tomi Ollila
2016-10-30 9:52 ` Jani Nikula
2016-10-30 20:53 ` Tomi Ollila
2016-11-02 18:46 ` [PATCH v3] " Jani Nikula
2016-11-11 20:29 ` Tomi Ollila
2016-11-12 11:43 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).