Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: preexec function to work after `&&'



* 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@xxxxxxxxxxxxxxxx   | one be warm |
ENST Br, BP 832, 29285 Brest, FRANCE | alone?"     |



Messages sorted by: Reverse Date, Date, Thread, Author