Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
preexec function to work after `&&'
- X-seq: zsh-users 6463
- From: Eric Smith <es@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: preexec function to work after `&&'
- Date: Wed, 13 Aug 2003 15:14:30 +0200
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author