zsh-users
 help / color / mirror / code / Atom feed
* Using Global aliases to make a "macro" shell
@ 2006-07-15 11:00 zzapper
  2006-07-15 16:05 ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: zzapper @ 2006-07-15 11:00 UTC (permalink / raw)
  To: zsh-users

Using Global aliases to make a "macro" shell

It took me a while to suss these

example:
> cp NF ND
Where NF means Newest File in directory and
ND is newsest directory

NF and ND are actually Global Aliases

alias -g ND='$(ls -d *(/om[1]))' # newset directory
alias -g NF='$(ls *(.om[1]))'    # newest file

Using these "primitives" ie NF,ND and others has saved me writing lots of 
repetive shell scripts.



-- 
http://successtheory.com/tips/ Vim, Zsh, MySQL Tips


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

* Re: Using Global aliases to make a "macro" shell
  2006-07-15 11:00 Using Global aliases to make a "macro" shell zzapper
@ 2006-07-15 16:05 ` Mikael Magnusson
  2006-07-15 16:22   ` zzapper
  2006-07-17  9:24   ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Mikael Magnusson @ 2006-07-15 16:05 UTC (permalink / raw)
  To: zsh-users; +Cc: zzapper

On 7/15/06, zzapper <david@tvis.co.uk> wrote:
> Using Global aliases to make a "macro" shell
>
> It took me a while to suss these
>
> example:
> > cp NF ND
> Where NF means Newest File in directory and
> ND is newsest directory
>
> NF and ND are actually Global Aliases
>
> alias -g ND='$(ls -d *(/om[1]))' # newset directory
> alias -g NF='$(ls *(.om[1]))'    # newest file
>
> Using these "primitives" ie NF,ND and others has saved me writing lots of
> repetive shell scripts.

A related very useful keybind is
bindkey "^N"      _most_recent_file
although it completes files and directories alike, despite the name.
Also very useful is
  bindkey "^[^N"    _most_accessed_file
Just copy _most_recent_file and apply
17c17
<   eval "file=($PREFIX*$SUFFIX(om[${NUMERIC:-1}]N))"
---
>   eval "file=($PREFIX*$SUFFIX(oa[${NUMERIC:-1}]N))"
21c21
<   eval "file=($PREFIX*$SUFFIX(om[${NUMERIC:-1}]N))"
---
>   eval "file=($PREFIX*$SUFFIX(oa[${NUMERIC:-1}]N))"

PS why the ls invocations? this seems to work just as well
alias -g NF='*(.om[1])'
alias -g ND='*(/om[1])'

-- 
Mikael Magnusson


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

* Re: Using Global aliases to make a "macro" shell
  2006-07-15 16:05 ` Mikael Magnusson
@ 2006-07-15 16:22   ` zzapper
  2006-07-15 19:46     ` Mikael Magnusson
  2006-07-17  9:24   ` Peter Stephenson
  1 sibling, 1 reply; 6+ messages in thread
From: zzapper @ 2006-07-15 16:22 UTC (permalink / raw)
  To: zsh-users

"Mikael Magnusson" <mikachu@gmail.com> wrote in
news:237967ef0607150905v400bac6cl9dc9add48786074a@mail.gmail.com: 

> On 7/15/06, zzapper <david@tvis.co.uk> wrote:
>> Using Global aliases to make a "macro" shell
>>
> A related very useful keybind is
> bindkey "^N"      _most_recent_file
> although it completes files and directories alike, despite the name.
> Also very useful is
>   bindkey "^[^N"    _most_accessed_file
> Just copy _most_recent_file and apply
> 17c17
> <   eval "file=($PREFIX*$SUFFIX(om[${NUMERIC:-1}]N))"
> ---
>>   eval "file=($PREFIX*$SUFFIX(oa[${NUMERIC:-1}]N))"
> 21c21
> <   eval "file=($PREFIX*$SUFFIX(om[${NUMERIC:-1}]N))"
> ---
>>   eval "file=($PREFIX*$SUFFIX(oa[${NUMERIC:-1}]N))"
> 
> PS why the ls invocations? this seems to work just as well
> alias -g NF='*(.om[1])'
> alias -g ND='*(/om[1])'
> 
Thanks that's why I post these to see how to do it better!
BTW I get _most_accessed_file widget not available (zsh 4.2.6) what Do I 
have to do activate it?
zzapper


-- 
http://successtheory.com/tips/ Vim, Zsh, MySQL Tips


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

* Re: Using Global aliases to make a "macro" shell
  2006-07-15 16:22   ` zzapper
@ 2006-07-15 19:46     ` Mikael Magnusson
  2006-07-15 22:22       ` zzapper
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2006-07-15 19:46 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

On 7/15/06, zzapper <david@tvis.co.uk> wrote:
> "Mikael Magnusson" <mikachu@gmail.com> wrote in
> news:237967ef0607150905v400bac6cl9dc9add48786074a@mail.gmail.com:
>
> > On 7/15/06, zzapper <david@tvis.co.uk> wrote:
> >> Using Global aliases to make a "macro" shell
> >>
> > A related very useful keybind is
> > bindkey "^N"      _most_recent_file
> > although it completes files and directories alike, despite the name.
> > Also very useful is
> >   bindkey "^[^N"    _most_accessed_file
> > Just copy _most_recent_file and apply
> > 17c17
> > <   eval "file=($PREFIX*$SUFFIX(om[${NUMERIC:-1}]N))"
> > ---
> >>   eval "file=($PREFIX*$SUFFIX(oa[${NUMERIC:-1}]N))"
> > 21c21
> > <   eval "file=($PREFIX*$SUFFIX(om[${NUMERIC:-1}]N))"
> > ---
> >>   eval "file=($PREFIX*$SUFFIX(oa[${NUMERIC:-1}]N))"
> >
> > PS why the ls invocations? this seems to work just as well
> > alias -g NF='*(.om[1])'
> > alias -g ND='*(/om[1])'
> >
> Thanks that's why I post these to see how to do it better!
> BTW I get _most_accessed_file widget not available (zsh 4.2.6) what Do I
> have to do activate it?

Yeah, you have to do what i wrote you have to do :). It's a widget i
created by copying and modifying _most_recent_file.

-- 
Mikael Magnusson


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

* Re: Using Global aliases to make a "macro" shell
  2006-07-15 19:46     ` Mikael Magnusson
@ 2006-07-15 22:22       ` zzapper
  0 siblings, 0 replies; 6+ messages in thread
From: zzapper @ 2006-07-15 22:22 UTC (permalink / raw)
  To: zsh-users

"Mikael Magnusson" <mikachu@gmail.com> wrote in 
news:237967ef0607151246w6e5dd938pe580adcd67eaa553@mail.gmail.com:

>  _most_recent_file
> 
MM
My Mistake I meant I don't seem to have4  _most_recent_file



-- 
http://successtheory.com/tips/ Vim, Zsh, MySQL Tips


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

* Re: Using Global aliases to make a "macro" shell
  2006-07-15 16:05 ` Mikael Magnusson
  2006-07-15 16:22   ` zzapper
@ 2006-07-17  9:24   ` Peter Stephenson
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2006-07-17  9:24 UTC (permalink / raw)
  To: zsh-users

"Mikael Magnusson" wrote:
> A related very useful keybind is
> bindkey "^N"      _most_recent_file
> although it completes files and directories alike, despite the name.
> Also very useful is
>   bindkey "^[^N"    _most_accessed_file

You can get this effect without actually using any new widgets with the
"generic" method.  See "From Bash to Zsh" page 407, though it gets
posted here every now and then, too.

For the effect of _most_recent_file, except that menu completion is
active so you can cycle back through previously modified files:

  zstyle ':completion:most-recent-file:*' match-original both
  zstyle ':completion:most-recent-file::::' completer _menu _files _match
  zstyle ':completion:most-recent-file:*' file-sort modification
  zstyle ':completion:most-recent-file:*' file-patterns '*:all\ files'
  zstyle ':completion:most-recent-file:*' hidden all
  zle -C most-recent-file menu-complete _generic

(and bind "most-recent-file" to a key).  The "hidden" style removes the
completion list.  The presence of the "_match" completer and the
"match-original" style allow you to complete patterns:  first it tries
to complete as if there were a pattern already there, then it inserts a
"*".

For the effect of _most_accessed_file, replace "modification" in the
"file-sort" style by "access" (and rename the contexts and widget).

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

end of thread, other threads:[~2006-07-17  9:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-15 11:00 Using Global aliases to make a "macro" shell zzapper
2006-07-15 16:05 ` Mikael Magnusson
2006-07-15 16:22   ` zzapper
2006-07-15 19:46     ` Mikael Magnusson
2006-07-15 22:22       ` zzapper
2006-07-17  9:24   ` Peter Stephenson

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