zsh-users
 help / color / mirror / code / Atom feed
* "Fallback" alias/function in zsh
@ 1998-12-08 22:04 Paul Moore
  1998-12-08 23:50 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Moore @ 1998-12-08 22:04 UTC (permalink / raw)
  To: zsh-users

Hi,
Is it possible to define a function which gets used whenever zsh's
normal alias/function/builtin/path lookup fails? The best example I can
give of what I'm after is using zsh for Win32 (which is version 3.0.5).
There, I'd like to have access to the good old CMD.EXE builtins, like
DIR (at the moment, I don't have a working Unix-like ls). So, I thought,
how about defining a function to be called "when all else fails" which
does "CMD /C <the command I typed>"? But I couldn't find a way of doing
this.

Is it possible, or if not, would it be a useful addition?

Paul Moore


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

* Re: "Fallback" alias/function in zsh
  1998-12-08 22:04 "Fallback" alias/function in zsh Paul Moore
@ 1998-12-08 23:50 ` Bart Schaefer
  1998-12-09  1:19   ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1998-12-08 23:50 UTC (permalink / raw)
  To: Paul Moore, zsh-users

On Dec 8, 10:04pm, Paul Moore wrote:
> Subject: "Fallback" alias/function in zsh
>
> Is it possible to define a function which gets used whenever zsh's
> normal alias/function/builtin/path lookup fails?

In 3.1.5, there's the preexec() function, in which you could do something
like this:

  function preexec() {
    command=("$@")
  }
  function precmd() {
    (($?)) && CMD /C "$command[@]"
  }

That means, before executing the command, save it in $command; then, after
executing it (and just before printing the prompt) if the exit status was
nonzero, attempt to execute the command with CMD /C.

This will do unusual things when you execute compound commands (separated
with ; && || etc.) and won't work for backgrounded commands (&) but should
do what you want for simple commands typed at the prompt.

Of course, 3.1.5 isn't ported to Windows yet ...


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

* Re: "Fallback" alias/function in zsh
  1998-12-08 23:50 ` Bart Schaefer
@ 1998-12-09  1:19   ` Phil Pennock
  1998-12-09  2:55     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Pennock @ 1998-12-09  1:19 UTC (permalink / raw)
  To: zsh-users

Typing away merrily, Bart Schaefer produced the immortal words:
> In 3.1.5, there's the preexec() function, in which you could do something
> like this:
> 
>   function preexec() {
>     command=("$@")
>   }
>   function precmd() {
>     (($?)) && CMD /C "$command[@]"
>   }
[...]
> This will do unusual things when you execute compound commands (separated
> with ; && || etc.) and won't work for backgrounded commands (&) but should
> do what you want for simple commands typed at the prompt.

That seems dangerous.  The problem looks to be 'if path lookup fails'
not 'if path lookup fails or program returns non-zero'; could be fun to
run a grep(1) port and have it run twice if no matches were found ...
-- 
--> Phil Pennock ; GAT d- s+:+ a22 C++(++++) UL++++/I+++/S+++/H+ P++@ L+++
E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++ DI+ D+
G+ e+ h* r y?


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

* Re: "Fallback" alias/function in zsh
  1998-12-09  1:19   ` Phil Pennock
@ 1998-12-09  2:55     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 1998-12-09  2:55 UTC (permalink / raw)
  To: zsh-users

On Dec 9,  1:19am, Phil Pennock wrote:
} Subject: Re: "Fallback" alias/function in zsh
}
} Typing away merrily, Bart Schaefer produced the immortal words:
} > In 3.1.5, there's the preexec() function, in which you could do something
} > like this:
} > 
} >   function preexec() {
} >     command=("$@")
} >   }
} >   function precmd() {
} >     (($?)) && CMD /C "$command[@]"
} >   }
} 
} That seems dangerous.  The problem looks to be 'if path lookup fails'
} not 'if path lookup fails or program returns non-zero'; could be fun to
} run a grep(1) port and have it run twice if no matches were found ...

Easily enough adjusted:

  function precmd() {
    (($?)) && { whence "$command[1]" >& /dev/null || CMD /C "$command[@]" }
  }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

end of thread, other threads:[~1998-12-09  2:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-08 22:04 "Fallback" alias/function in zsh Paul Moore
1998-12-08 23:50 ` Bart Schaefer
1998-12-09  1:19   ` Phil Pennock
1998-12-09  2:55     ` Bart Schaefer

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).