mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-02 22:11:54 +02:00
23518: MIME styles find-file-in-path and file-path.
This commit is contained in:
parent
023f6ce4e1
commit
1fbe843687
3 changed files with 59 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2007-06-04 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* 23518: Doc/Zsh/contrib.yo, Functions/MIME/zsh-mime-handler:
|
||||||
|
add find-file-in-path and file-path styles to MIME system.
|
||||||
|
|
||||||
2007-06-03 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
2007-06-03 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
* 23511: Src/exec.c, Src/lex.c: error if here document
|
* 23511: Src/exec.c, Src/lex.c: error if here document
|
||||||
|
|
|
@ -1510,12 +1510,14 @@ It is recommended that a trailing tt(*) (suitably quoted) be appended
|
||||||
to style patterns in case the system is extended in future. Some
|
to style patterns in case the system is extended in future. Some
|
||||||
examples are given below.
|
examples are given below.
|
||||||
startitem()
|
startitem()
|
||||||
|
kindex(current-shell, MIME style)
|
||||||
item(tt(current-shell))(
|
item(tt(current-shell))(
|
||||||
If this boolean style is true, the mailcap handler for the context in
|
If this boolean style is true, the mailcap handler for the context in
|
||||||
question is run using the tt(eval) builtin instead of by starting a new
|
question is run using the tt(eval) builtin instead of by starting a new
|
||||||
tt(sh) process. This is more efficient, but may not work in the occasional
|
tt(sh) process. This is more efficient, but may not work in the occasional
|
||||||
cases where the mailcap handler uses strict POSIX syntax.
|
cases where the mailcap handler uses strict POSIX syntax.
|
||||||
)
|
)
|
||||||
|
kindex(execute-as-is, MIME style)
|
||||||
item(tt(execute-as-is))(
|
item(tt(execute-as-is))(
|
||||||
This style gives a list of patterns to be matched against files
|
This style gives a list of patterns to be matched against files
|
||||||
passed for execution with a handler program. If the file matches
|
passed for execution with a handler program. If the file matches
|
||||||
|
@ -1527,10 +1529,36 @@ hence executable files are executed directly and not passed to a
|
||||||
handler, and the option tt(AUTO_CD) may be used to change to directories
|
handler, and the option tt(AUTO_CD) may be used to change to directories
|
||||||
that happen to have MIME suffixes.
|
that happen to have MIME suffixes.
|
||||||
)
|
)
|
||||||
|
kindex(file-path, MIME style)
|
||||||
|
item(tt(file-path))(
|
||||||
|
Used if the style tt(find-file-in-path) is true for the same context.
|
||||||
|
Set to an array of directories that are used for searching for the
|
||||||
|
file to be handled; the default is the command path given by the
|
||||||
|
special parameter tt(path). The shell option tt(PATH_DIRS) is respected;
|
||||||
|
if that is set, the appropriate path will be searched even if the
|
||||||
|
name of the file to be handled as it appears on the command line contains
|
||||||
|
a `tt(/)'.
|
||||||
|
The full context is tt(:mime:.)var(suffix)tt(:), as described for the style
|
||||||
|
tt(handler).
|
||||||
|
)
|
||||||
|
kindex(find-file-in-path, MIME style)
|
||||||
|
item(tt(find-file-in-path))(
|
||||||
|
If set, allows files whose names do not contain absolute paths
|
||||||
|
to be searched for in the command path or the path specified by the
|
||||||
|
tt(file-path) style. If the file is not found in the path, it is looked
|
||||||
|
for locally (whether or not the current directory is in the path); if it is
|
||||||
|
not found locally, the handler will abort unless the tt(handle-nonexistent)
|
||||||
|
style is set. Files found in the path are tested as described for
|
||||||
|
the style tt(execute-as-is).
|
||||||
|
The full context is tt(:mime:.)var(suffix)tt(:), as described for the style
|
||||||
|
tt(handler).
|
||||||
|
)
|
||||||
|
kindex(flags, MIME style)
|
||||||
item(tt(flags))(
|
item(tt(flags))(
|
||||||
Defines flags to go with a handler; the context is as for the
|
Defines flags to go with a handler; the context is as for the
|
||||||
tt(handler) style, and the format is as for the flags in tt(mailcap).
|
tt(handler) style, and the format is as for the flags in tt(mailcap).
|
||||||
)
|
)
|
||||||
|
kindex(handle-nonexistent, MIME style)
|
||||||
item(tt(handle-nonexistent))(
|
item(tt(handle-nonexistent))(
|
||||||
By default, arguments that don't correspond to files are not passed
|
By default, arguments that don't correspond to files are not passed
|
||||||
to the MIME handler in order to prevent it from intercepting commands found
|
to the MIME handler in order to prevent it from intercepting commands found
|
||||||
|
@ -1539,7 +1567,10 @@ an array of extended glob patterns for arguments that will be passed to the
|
||||||
handler even if they don't exist. If it is not explicitly set it
|
handler even if they don't exist. If it is not explicitly set it
|
||||||
defaults to tt([[:alpha:]]#:/*) which allows URLs to be passed to the MIME
|
defaults to tt([[:alpha:]]#:/*) which allows URLs to be passed to the MIME
|
||||||
handler even though they don't exist in that format in the file system.
|
handler even though they don't exist in that format in the file system.
|
||||||
|
The full context is tt(:mime:.)var(suffix)tt(:), as described for the style
|
||||||
|
tt(handler).
|
||||||
)
|
)
|
||||||
|
kindex(handler, MIME style)
|
||||||
item(tt(handler))(
|
item(tt(handler))(
|
||||||
Specifies a handler for a suffix; the suffix is given by the context as
|
Specifies a handler for a suffix; the suffix is given by the context as
|
||||||
tt(:mime:.)var(suffix)tt(:), and the format of the handler is exactly
|
tt(:mime:.)var(suffix)tt(:), and the format of the handler is exactly
|
||||||
|
@ -1550,12 +1581,14 @@ the tt(flags) style should be set to include the word tt(needsterminal),
|
||||||
or if the output is to be displayed through a pager (but not if the
|
or if the output is to be displayed through a pager (but not if the
|
||||||
handler is itself a pager), it should include tt(copiousoutput).
|
handler is itself a pager), it should include tt(copiousoutput).
|
||||||
)
|
)
|
||||||
|
kindex(mailcap, MIME style)
|
||||||
item(tt(mailcap))(
|
item(tt(mailcap))(
|
||||||
A list of files in the format of tt(~/.mailcap) and
|
A list of files in the format of tt(~/.mailcap) and
|
||||||
tt(/etc/mailcap) to be read during setup, replacing the default list
|
tt(/etc/mailcap) to be read during setup, replacing the default list
|
||||||
which consists of those two files. The context is tt(:mime:).
|
which consists of those two files. The context is tt(:mime:).
|
||||||
A tt(PLUS()) in the list will be replaced by the default files.
|
A tt(PLUS()) in the list will be replaced by the default files.
|
||||||
)
|
)
|
||||||
|
kindex(mailcap-priorities, MIME style)
|
||||||
item(tt(mailcap-priorities))(
|
item(tt(mailcap-priorities))(
|
||||||
This style is used to resolve multiple mailcap entries for the same MIME
|
This style is used to resolve multiple mailcap entries for the same MIME
|
||||||
type. It consists of an array of the following elements, in descending
|
type. It consists of an array of the following elements, in descending
|
||||||
|
@ -1585,6 +1618,7 @@ enditem()
|
||||||
Note that as this style is handled during initialisation, the context
|
Note that as this style is handled during initialisation, the context
|
||||||
is always tt(:mime:), with no discrimination by suffix.
|
is always tt(:mime:), with no discrimination by suffix.
|
||||||
)
|
)
|
||||||
|
kindex(mailcap-prio-flags, MIME style)
|
||||||
item(tt(mailcap-prio-flags))(
|
item(tt(mailcap-prio-flags))(
|
||||||
This style is used when the keyword tt(flags) is encountered in the
|
This style is used when the keyword tt(flags) is encountered in the
|
||||||
list of tests specified by the tt(mailcap-priorities) style.
|
list of tests specified by the tt(mailcap-priorities) style.
|
||||||
|
@ -1594,18 +1628,21 @@ assignments found with some entries in the mailcap file). Earlier
|
||||||
patterns in the list are preferred to later ones, and matched patterns
|
patterns in the list are preferred to later ones, and matched patterns
|
||||||
are preferred to unmatched ones.
|
are preferred to unmatched ones.
|
||||||
)
|
)
|
||||||
|
kindex(mime-types, MIME style)
|
||||||
item(tt(mime-types))(
|
item(tt(mime-types))(
|
||||||
A list of files in the format of tt(~/.mime.types) and
|
A list of files in the format of tt(~/.mime.types) and
|
||||||
tt(/etc/mime.types) to be read during setup, replacing the default list
|
tt(/etc/mime.types) to be read during setup, replacing the default list
|
||||||
which consists of those two files. The context is tt(:mime:).
|
which consists of those two files. The context is tt(:mime:).
|
||||||
A tt(PLUS()) in the list will be replaced by the default files.
|
A tt(PLUS()) in the list will be replaced by the default files.
|
||||||
)
|
)
|
||||||
|
kindex(never-background, MIME style)
|
||||||
item(tt(never-background))(
|
item(tt(never-background))(
|
||||||
If this boolean style is set, the handler for the given context is
|
If this boolean style is set, the handler for the given context is
|
||||||
always run in the foreground, even if the flags provided in the mailcap
|
always run in the foreground, even if the flags provided in the mailcap
|
||||||
entry suggest it need not be (for example, it doesn't require a
|
entry suggest it need not be (for example, it doesn't require a
|
||||||
terminal).
|
terminal).
|
||||||
)
|
)
|
||||||
|
kindex(pager, MIME style)
|
||||||
item(tt(pager))(
|
item(tt(pager))(
|
||||||
If set, will be used instead of tt($PAGER) or tt(more) to handle
|
If set, will be used instead of tt($PAGER) or tt(more) to handle
|
||||||
suffixes where the tt(copiousoutput) flag is set. The context is
|
suffixes where the tt(copiousoutput) flag is set. The context is
|
||||||
|
|
|
@ -64,6 +64,22 @@ zstyle -a $context handle-nonexistent hand_nonex ||
|
||||||
local pattern
|
local pattern
|
||||||
local -a files
|
local -a files
|
||||||
|
|
||||||
|
# Search some path for the file, if required.
|
||||||
|
# We do this before any other tests that need to find the
|
||||||
|
# actual file or its directory.
|
||||||
|
local dir
|
||||||
|
local -a filepath
|
||||||
|
if zstyle -t $context find-file-in-path && [[ $1 != /* ]] &&
|
||||||
|
[[ $1 != */* || -o pathdirs ]]; then
|
||||||
|
zstyle -a $context file-path filepath || filepath=($path)
|
||||||
|
for dir in $filepath; do
|
||||||
|
if [[ -e $dir/$1 ]]; then
|
||||||
|
1=$dir/$1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# In case the pattern contains glob qualifiers, as it does by default,
|
# In case the pattern contains glob qualifiers, as it does by default,
|
||||||
# we need to do real globbing, not just pattern matching.
|
# we need to do real globbing, not just pattern matching.
|
||||||
# The strategy is to glob the files in the directory using the
|
# The strategy is to glob the files in the directory using the
|
||||||
|
@ -111,7 +127,6 @@ zstyle -t $context current-shell && no_sh=yes
|
||||||
# terminal and display is set.
|
# terminal and display is set.
|
||||||
zstyle -t $context never-background && no_bg=yes
|
zstyle -t $context never-background && no_bg=yes
|
||||||
|
|
||||||
local -a files
|
|
||||||
local hasmeta stdin
|
local hasmeta stdin
|
||||||
|
|
||||||
# See if the handler has shell metacharacters in.
|
# See if the handler has shell metacharacters in.
|
||||||
|
@ -120,7 +135,7 @@ if [[ $handler = *[\\\;\*\?\|\"\'\`\$]* ]]; then
|
||||||
hasmeta=1
|
hasmeta=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a execargs
|
local -a execargs files
|
||||||
|
|
||||||
if [[ $handler = *%s* ]]; then
|
if [[ $handler = *%s* ]]; then
|
||||||
# We need to replace %s with the file(s).
|
# We need to replace %s with the file(s).
|
||||||
|
|
Loading…
Reference in a new issue