zsh-users
 help / color / mirror / code / Atom feed
From: Eric Smith <es@fruitcom.com>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: preexec function to work after `&&'
Date: Wed, 13 Aug 2003 15:14:30 +0200	[thread overview]
Message-ID: <20030813131429.GA2413@fruitcom.com> (raw)

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


             reply	other threads:[~2003-08-13 13:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-13 13:14 Eric Smith [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030813131429.GA2413@fruitcom.com \
    --to=es@fruitcom.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).