1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-04 22:51:42 +02:00

20199: improve MIME handling.

This commit is contained in:
Peter Stephenson 2004-07-26 16:59:53 +00:00
parent 17e576782c
commit 8c9a6b01d1
9 changed files with 175 additions and 7 deletions

View file

@ -1,5 +1,13 @@
2004-07-26 Peter Stephenson <pws@csr.com>
* 20199: Completion/Unix/Command/_elinks,
Completion/Unix/Type/.distfiles, Completion/Unix/Type/_mime_types,
Completion/X/Command/.distfiles, Completion/X/Command/_kfmclient,
Doc/Zsh/contrib.yo, Functions/MIME/pick-web-browser,
Functions/MIME/zsh-mime-setup: add completion for MIME types
and kfmclient, use kfmclient to talk to konqueror and
improve mime-types and mailcap styles.
* 20198: Src/exec.c, Src/signals.c, Test/C03traps.ztst,
Test/Makefile.in, Test/ztst.zsh: EXIT traps were freed before
being run. This isn't recommended by most programming text books.

View file

@ -11,7 +11,7 @@ _arguments -C -A '-*' \
'*-base-session[clone session with given ID]:ID number:' \
'*-confdir[set config dir to given string]:configuration directory:_files -/' \
'*-conffile[configuration file name]:configuration file:_files' \
'*-default-mime-type[MIME type to assume for documents]:MIME type:' \
'*-default-mime-type[MIME type to assume for documents]:MIME type:_mime_types' \
'*-dump[write formatted version of given URL to stdout]::boolean:(0 1)' \
'*-dump-charset[codepage to use with -dump]:codepage:' \
'*-dump-width[width of document formatted with -dump]:width:' \

View file

@ -10,4 +10,5 @@ _groups _perl_basepods _signals _users_on
_hosts _tar_archive _time_zone
_file_systems _net_interfaces _terminals _locales
_java_class _services _email_addresses _global_tags
_mime_types
'

View file

@ -0,0 +1,42 @@
#autoload
local expl maintype
local -a default_type_files type_files match mbegin mend
integer ind
default_type_files=(~/.mime.types /etc/mime.types)
# This is the same style as used by zsh-mime-setup, with a different
# context.
if zstyle -a ":completion:${curcontext}:mime" mime-types type_files; then
while (( (ind = ${type_files[(I)+]}) > 0 )); do
type_files[$ind]=($default_type_files)
done
else
type_files=($default_type_files)
fi
#
# Handle two different mime type formats; the simple
# format:
# application/x-pws-frobnicate psf pwsf
# and the extended format
# type=application/x-pws-frobnicate \
# desc="PWS frobnicated widget" \
# exts="pwsf,psf"
# which Netscape seems to like.
#
if [[ $PREFIX = (#b)([^/]##)/* ]]; then
# Search for subtype.
maintype=$match[1]
compset -p $(( ${#maintype} + 1 ))
_wanted mimesubtype expl 'MIME subtype' \
compadd -- $(sed -ne "s%^\(type=\|\)${maintype}/\([^ ]*\).*$%\2%p" \
$type_files)
else
# Search for main type.
_wanted mimetype expl 'MIME type' \
compadd -S/ -- $(sed -ne "s/^type=//" \
-e "s%^\(${PREFIX:-[a-z]}[^=\"]*\)/.*$%\1%p" $type_files)
fi

View file

@ -3,4 +3,5 @@ DISTFILES_SRC='
_gv _netscape _xauth _xfig _mozilla _xterm _xwit
_nedit _vnc _x_utils _xdvi _xmodmap _xset _xv
_acroread _dcop _gqview _xloadimage _mplayer
_kfmclient
'

93
Completion/X/Command/_kfmclient Executable file
View file

@ -0,0 +1,93 @@
#compdef kfmclient
local expl
local -a context state line
typeset -A opt_args
_arguments \
'--help[show help message]' \
'--help-qt[show Qt specific options]' \
'--help-kde[show KDE specific options]' \
'--help-all[show all options]' \
'--author[show author information]' \
'-v[show version information]' \
'--version[show version information]' \
'--license[show license information]' \
'--commands[show available commands]' \
'--display=:X display:_x_display' \
'--session=:session id for restoring application: ' \
'--cmap[use private colormap (8-bit display)]' \
'--ncols=:limit on number of colors (8-bit display): ' \
'--nograb[never grab mouse or keyboard]' \
'--dograb[override nograb in debugger]' \
'--sync[switch to synchronous mode when debugging]' \
'--fn=:font name:_x_font' \
'--font=:font name:_x_font' \
'--bg=:background color:_x_color' \
'--background=:background color:_x_color' \
'--fg=:foreground color:_x_color' \
'--foreround=:foreground color:_x_color' \
'--btn=:button color:_x_color' \
'--button=:button color:_x_color' \
'--name=:application name: ' \
'--title=:application title (caption): ' \
'--visual=:specify visual:_x_visual' \
'--inputstyle:X input method:(onthespot overthespot offthespot root)' \
'--im:X Input Method server: ' \
'--noxim[disable X Input Method]' \
'--reverse[reverse widget layout]' \
'--caption=:name in titlebar: ' \
'--icon=:application icon: ' \
'--miniicon=:icon in titlebar: ' \
'--config=:configuration file:_files' \
'--dcopserver=:DCOP server: ' \
'--nocrashhandler[disable crash handler, allow core dumps]' \
'--waitforwm[Wait for a WM_NET compatible window manager]' \
'--style=:GUI style for application: ' \
'--geometry=:client window geometry:_x_geometry' \
'1:client command:(openURL openProfile openProperties exec move
download copy sortDesktop configure configureDesktop)' \
'2::args:->firstarg' \
'3::args:->secondarg' && return 0
[[ $state = *arg ]] || return 1
# Argument to previous command.
print $line >/tmp/tmp.out
case $line[1] in
(openURL)
if [[ $state = secondarg ]]; then
_mime_types && return 0
elif [[ $state = firstarg ]]; then
_urls && return 0
fi
;;
(openProfile)
if [[ $state = secondarg ]]; then
_urls && return 0
elif [[ $state = firstarg ]]; then
_wanted profile expl 'Konqueror profile' \
compadd -- ~/.kde/share/apps/konqueror/profiles/*(:t) && return 0
fi
;;
(exec)
if [[ $state = secondarg ]]; then
# TODO: could probe inside Desktop files.
_message "KDE binding" && return 0
elif [[ $state = firstarg ]]; then
_urls && return 0
fi
;;
(move|download|openProperties)
if [[ $state = firstarg ]]; then
_urls && return 0
fi
;;
esac
_message "no more arguments"

View file

@ -1045,11 +1045,13 @@ item(mime-types)(
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
which consists of those two files. The context is tt(:mime:).
A tt(PLUS()) in the list will be replaced by the default files.
)
item(mailcap)(
A list of files in the format of tt(~/.mailcap) and
tt(/etc/mailcap) to be read during setup, replacing the default list
which consists of those two files. The context is tt(:mime:).
A tt(PLUS()) in the list will be replaced by the default files.
)
item(handler)(
Specifies a handler for a suffix; the suffix is given by the context as

View file

@ -82,8 +82,13 @@ if [[ -n $DISPLAY ]]; then
for browser in $xbrowsers; do
if [[ $windows[(I)(#i)$browser] -ne 0 ]]; then
if [[ $browser = konqueror ]]; then
# I'm sure there's documentation for this somewhere...
dcop $(dcop|grep konqueror) default openBrowserWindow $url
# kfmclient is less hairy and better supported than direct
# use of dcop. Run kfmclient --commands
# for more information. Note that as konqueror is a fully
# featured file manager, this will actually do complete
# MIME handling, not just web pages.
kfmclient openURL $url ||
dcop $(dcop|grep konqueror) default openBrowserWindow $url
else
# Mozilla bells and whistles are described at:
# http://www.mozilla.org/unix/remote.html

View file

@ -53,14 +53,30 @@ fi
# to handlers and their flags.
typeset -A suffix_type_map type_handler_map type_flags_map
local -a default_type_files default_cap_files
local -a type_files cap_files array match mbegin mend
local file line type suffix exts elt flags line2
integer ind
default_type_files=(~/.mime.types /etc/mime.types)
default_cap_files=(~/.mailcap /etc/mailcap)
# Customizable list of files to examine.
zstyle -a :mime: mime-types type_files ||
type_files=(~/.mime.types /etc/mime.types)
zstyle -a :mime: mailcap cap_files ||
cap_files=(~/.mailcap /etc/mailcap)
if zstyle -a :mime: mime-types type_files; then
while (( (ind = ${type_files[(I)+]}) > 0 )); do
type_files[$ind]=($default_type_files)
done
else
type_files=($default_type_files)
fi
if zstyle -a :mime: mailcap cap_files; then
while (( (ind = ${cap_files[(I)+]}) > 0 )); do
cap_files[$ind]=($default_cap_files)
done
else
cap_files=($default_cap_files)
fi
{
mime-setup-add-type() {