Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: MIME and completion ?



On Jan 30, 10:57am, Sylvain Meunier wrote:
}
} I would use MIME types with the zsh completion system when i use
} wildcards like * or ? for ignoring "uneditable" files.

First you need to describe the syntax of the file from which you
are obtaining your MIME type data.  ~/.mailcap and ~/.mime.types
have radically different formats, and there are probably some XML
files that describe MIME floating around as well.  For example, to
get all the file extensions for text files out of /etc/mime.types
you can use this parameter expansion:

${=${(M)${(f)"$(</etc/mime.types)"}:#text/*[[:space:]]*}#*[[:space:]]}

To break that down ...

mime_types=( ${(f)"$(</etc/mime.types)"} )
text_types=( ${(M)mime_types:#text/*[[:space:]]*} )
text_exts=( ${=text_types#*[[:space:]]} )

You probably want to add some things to that for which there are not
entries in /etc/mime.types, such as:

text_exts+=(c h sh)

Then you need to create zstyle entries for the commands to which
each MIME type applies.  Probably you want the ignored-patterns
style, which means you need to list the files you DO NOT want to
match.  Since extendedglob is on during completion, you can do
that by making a negated pattern (a leading caret, with the rest
of the pattern in parens).  Example:

zstyle ':completion::complete:(vi|vim):*' ignored-patterns \
	"^(*.(${(j:|:)text_exts}))"

Rinse and repeat for other types and commands.



Messages sorted by: Reverse Date, Date, Thread, Author