zsh-users
 help / color / mirror / code / Atom feed
* preexec function to work after `&&'
@ 2003-08-13 13:14 Eric Smith
  2003-08-13 15:16 ` Oliver Kiddle
  2003-09-08 19:17 ` Jesper Holmberg
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Smith @ 2003-08-13 13:14 UTC (permalink / raw)
  To: Zsh Users

Hi

This mime type like preexec makes life a lot more convenient
(for me anyways) by automatically launching the given file
with the associated application - but it don't work in a compound command
like sleep 1 && some.pdf (or whatever the file happens to be).

How might I fix this?

And while you are at it (if you are), how could I introduce case insensitivity
on the suffixes.

thank you....

function preexec {
local cmd
local application
cmd=(${(Q)${(z)3}})
if [[ $cmd[1] == (https*://*|http://|www.*.*|*.(html|HTML)) ]]; then
    application=w3m
elif [[ $cmd[1] == (*README*|*readme*|*.(svg|draft|conf|txt|xsl|xml|mail|csv)) ]]; then
    application=vim
elif [[ $cmd[1] == *.(pdf|PDF) ]]; then
    application=acroread
elif [[ $cmd[1] == *.(ps|PS) ]]; then
    application=gv
elif [[ $cmd[1] == *.(gif|jpg|jpeg|tif|tiff|png) ]]; then
    application=display
elif [[ $cmd[1] == *.(xls) ]]; then
    application=ooffice
    url=file:///
elif [[ $cmd[1] == *.(gz|GZ) ]]; then
    application=zless
elif [[ $cmd[1] == *.(doc) ]]; then
    application=abiword
elif [[ $cmd[1] == *.(rtf|RTF) ]]; then
    application=ted
fi
if [ $application ];then
    eval "function ${(q)cmd[1]} {
        unsetopt noglob
        $application $url${(q)cmd[1]}" '$*
        unfunction' "${(q)cmd[1]}
    }"
setopt noglob
fi

-- 
Eric Smith


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-09-10  7:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-13 13:14 preexec function to work after `&&' Eric Smith
2003-08-13 15:16 ` Oliver Kiddle
2003-09-08 19:17 ` Jesper Holmberg
2003-09-08 20:21   ` preexec function to work after `&&' -> tab completion for preexec Eric Smith
2003-09-10  7:51   ` preexec function to work after `&&' Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).