* 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
* Re: preexec function to work after `&&'
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
1 sibling, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2003-08-13 15:16 UTC (permalink / raw)
To: Eric Smith; +Cc: Zsh Users
Eric Smith wrote:
> 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?
With difficulty. Don't think you can.
I use something similar for mhshow. Other problem with this scheme is
that correction doesn't know about it. Perhaps we should allow a special
form of aliases to be patterns.
> And while you are at it (if you are), how could I introduce case insensitivity
> on the suffixes.
Put (#i) before the file patterns
Oliver
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: preexec function to work after `&&'
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
1 sibling, 2 replies; 5+ messages in thread
From: Jesper Holmberg @ 2003-09-08 19:17 UTC (permalink / raw)
To: Zsh Users
* On Wed Aug 13, Eric Smith wrote:
> 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
>
I only now found the time to experiment with Eric's neat preexec function,
and it's very nice. However, I'd like it to also work with tab completion,
is that possible?
I.e. say I have a file in my current directory called "foo.pdf". Writing
"./foo.pdf" on the command line starts acroread with the file as an
argument, just as I wanted, but I cannot type "./fo<tab>" and have a
completion of the file name. I'm not even sure this would be desirable in
the general case, as I'm normally not interested in completing regular
files in the first position, but would it be possible to for example
specify that files in the current directory should be completed? Or is
there a better way to solve this problem that I haven't thought about?
TIA,
Jesper
--
Jesper Holmberg |"But how can |
jesper.holmberg@enst-bretagne.fr | one be warm |
ENST Br, BP 832, 29285 Brest, FRANCE | alone?" |
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: preexec function to work after `&&' -> tab completion for preexec
2003-09-08 19:17 ` Jesper Holmberg
@ 2003-09-08 20:21 ` Eric Smith
2003-09-10 7:51 ` preexec function to work after `&&' Oliver Kiddle
1 sibling, 0 replies; 5+ messages in thread
From: Eric Smith @ 2003-09-08 20:21 UTC (permalink / raw)
To: Zsh Users
Hi
Alas I cannot take credit for this mimecap for the command line,
that is due to the redoubtable Bart Schaefer who replied to a
question I posted on the list. I just brainlessly extended it.
I use it constantly with screen(1) cutting and pasting and
could not imagine life without it. I have some function like
print -l (#i)*$1*
print matching files and then move up in screen copy mode to
the wanted file and hit a button and the file is pasted onto
the command line with enter automatically appended and the file
opens with its associated application. (This is made practical
by my quirky policy of not using subdirs much and having all files
in a single dir - using `_' to give descriptive "classes" to filenames).
Thanks Jesper for asking the question about completion. Its been on the tip of my
tongue for months - just did not get round to posting it.
ciao
> > fi
> >
>
> I only now found the time to experiment with Eric's neat preexec function,
> and it's very nice. However, I'd like it to also work with tab completion,
> is that possible?
>
> I.e. say I have a file in my current directory called "foo.pdf". Writing
> "./foo.pdf" on the command line starts acroread with the file as an
> argument, just as I wanted, but I cannot type "./fo<tab>" and have a
> completion of the file name. I'm not even sure this would be desirable in
> the general case, as I'm normally not interested in completing regular
> files in the first position, but would it be possible to for example
> specify that files in the current directory should be completed? Or is
> there a better way to solve this problem that I haven't thought about?
>
> TIA,
>
> Jesper
>
>
> --
> Jesper Holmberg |"But how can |
> jesper.holmberg@enst-bretagne.fr | one be warm |
> ENST Br, BP 832, 29285 Brest, FRANCE | alone?" |
--
Eric Smith
Fruitcom BV
Tel: +31 15 750 2364
Fax: +31 15 219 0524
Mobile: +31 6 551 76300
PO Box 2855
2601 CW Delft
The Netherlands
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: preexec function to work after `&&'
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 ` Oliver Kiddle
1 sibling, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2003-09-10 7:51 UTC (permalink / raw)
To: Jesper Holmberg; +Cc: Zsh Users
Jesper Holmberg wrote:
> I only now found the time to experiment with Eric's neat preexec function,
> and it's very nice. However, I'd like it to also work with tab completion,
> is that possible?
Not without modifying completion functions I don't think.
Completion in command context uses the -command- special context. By
default this ($_comps[-command-]) is the _autocd function. So the
easiest is perhaps to write your own wrapper function:
_cmd_or_file() {
_alternative \
'files:file:_path_files -g "(#i)*.(html|jpg|jpeg|tif|tiff|png|doc|xls)"' \
'commands:command:_autocd'
}
Then use this new function for the -command- context:
compdef _cmd_or_file -command-
Or you might find it easier to just get the latest 4.1 sources from CVS
and try out Peter's new suffix aliases feature.
Oliver
^ 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).