zsh-users
 help / color / mirror / code / Atom feed
* suffix alias on a generated file name
@ 2019-12-13 13:32 zzapper
  2019-12-14 11:17 ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: zzapper @ 2019-12-13 13:32 UTC (permalink / raw)
  To: zsh-users

Hi
I want to open the most recently editted text file with vim using a suffix 
alias

alias -s txt='gvim'
alias NF='*(.om[1])'
touch fred.txt
NF<tab>
*(.om[1])<TAB>
So double-tabbing will then exercise the suffix alias and open fred.txt in 
gvim.

BUT how do I do that without the manual TABing?


-- 
zzapper
https://twitter.com/dailyzshtip


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

* Re: suffix alias on a generated file name
  2019-12-13 13:32 suffix alias on a generated file name zzapper
@ 2019-12-14 11:17 ` Daniel Shahaf
  2019-12-15 16:20   ` zzapper
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2019-12-14 11:17 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

zzapper wrote on Fri, Dec 13, 2019 at 13:32:37 -0000:
> Hi
> I want to open the most recently editted text file with vim using a suffix 
> alias
> 
> alias -s txt='gvim'
> alias NF='*(.om[1])'
> touch fred.txt
> NF<tab>
> *(.om[1])<TAB>
> So double-tabbing will then exercise the suffix alias and open fred.txt in 
> gvim.
> 
> BUT how do I do that without the manual TABing?

What's wrong with

alias NF='gvim *.txt(.om[1])'

?

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

* Re: suffix alias on a generated file name
  2019-12-14 11:17 ` Daniel Shahaf
@ 2019-12-15 16:20   ` zzapper
  2019-12-16  3:58     ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: zzapper @ 2019-12-15 16:20 UTC (permalink / raw)
  To: zsh-users

Daniel Shahaf <d.s@daniel.shahaf.name> wrote in
news:20191214111751.ot4jd3o5esekqyfb@tarpaulin.shahaf.local2: 


>> BUT how do I do that without the manual TABing?
> 
> What's wrong with
> 
> alias NF='gvim *.txt(.om[1])'
> 
> ?
> 
> 
That would be a work-around but what I'm looking for is more generic 
solution perhaps useful for other situations i.e. having generated a 
filename or command to re-present it to the shell so that I can in this 
case apply a suffix alias.


-- 
zzapper
https://twitter.com/dailyzshtip


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

* Re: suffix alias on a generated file name
  2019-12-15 16:20   ` zzapper
@ 2019-12-16  3:58     ` Daniel Shahaf
  2019-12-17 10:02       ` zzapper
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2019-12-16  3:58 UTC (permalink / raw)
  To: zsh-users

zzapper wrote on Sun, Dec 15, 2019 at 16:20:16 -0000:
> Daniel Shahaf <d.s@daniel.shahaf.name> wrote in
> news:20191214111751.ot4jd3o5esekqyfb@tarpaulin.shahaf.local2: 
> 
> 
> >> BUT how do I do that without the manual TABing?
> > 
> > What's wrong with
> > 
> > alias NF='gvim *.txt(.om[1])'
> > 
> > ?
> > 
> > 
> That would be a work-around but what I'm looking for is more generic 
> solution perhaps useful for other situations i.e. having generated a 
> filename or command to re-present it to the shell so that I can in this 
> case apply a suffix alias.

I suppose you could wrap the accept-line widget to perform expansion:

    accept-line() { zle expand-word; zle .accept-line -- "$@" 
    zle -N accept-line

(untested)

You could even make it perform repeated expansions until $BUFFER doesn't change.


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

* Re: suffix alias on a generated file name
  2019-12-16  3:58     ` Daniel Shahaf
@ 2019-12-17 10:02       ` zzapper
  2019-12-17 10:14         ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: zzapper @ 2019-12-17 10:02 UTC (permalink / raw)
  To: zsh-users

Daniel Shahaf <d.s@daniel.shahaf.name> wrote in
news:20191216035801.doeloio2cwauxguj@tarpaulin.shahaf.local2: 

> zzapper wrote on Sun, Dec 15, 2019 at 16:20:16 -0000:
>> Daniel Shahaf <d.s@daniel.shahaf.name> wrote in
>> news:20191214111751.ot4jd3o5esekqyfb@tarpaulin.shahaf.local2: 
>> 
>> 
>> >> BUT how do I do that without the manual TABing?
>> > 

> I suppose you could wrap the accept-line widget to perform expansion:
> 
>     accept-line() { zle expand-word; zle .accept-line -- "$@" 
>     zle -N accept-line
> 
> (untested)
> 
Daniel nothing seems to work I think there must be something 'funny' about 
the way a suffix alias works i.e it must be the first thing that the shell 
sees.



-- 
zzapper
https://twitter.com/dailyzshtip


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

* Re: suffix alias on a generated file name
  2019-12-17 10:02       ` zzapper
@ 2019-12-17 10:14         ` Daniel Shahaf
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Shahaf @ 2019-12-17 10:14 UTC (permalink / raw)
  To: zsh-users

zzapper wrote on Tue, 17 Dec 2019 10:02 +00:00:
> Daniel Shahaf <d.s@daniel.shahaf.name> wrote in
> news:20191216035801.doeloio2cwauxguj@tarpaulin.shahaf.local2: 
> 
> > zzapper wrote on Sun, Dec 15, 2019 at 16:20:16 -0000:
> >> Daniel Shahaf <d.s@daniel.shahaf.name> wrote in
> >> news:20191214111751.ot4jd3o5esekqyfb@tarpaulin.shahaf.local2: 
> >> 
> >> 
> >> >> BUT how do I do that without the manual TABing?
> >> > 
> 
> > I suppose you could wrap the accept-line widget to perform expansion:
> > 
> >     accept-line() { zle expand-word; zle .accept-line -- "$@" 
> >     zle -N accept-line
> > 
> > (untested)
> > 
> Daniel nothing seems to work I think there must be something 'funny' about 
> the way a suffix alias works i.e it must be the first thing that the shell 
> sees.

Aliases _are_ parsed very early (see zshexpn(1) near the top), but zle
widgets run even earlier than that, before the command-line is parsed at
all.

What the example code does is change the meaning of pressing
<Enter> so it's like pressing <Tab><Enter>. That's what you wanted to
do, isn't it?

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

end of thread, other threads:[~2019-12-17 10:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-13 13:32 suffix alias on a generated file name zzapper
2019-12-14 11:17 ` Daniel Shahaf
2019-12-15 16:20   ` zzapper
2019-12-16  3:58     ` Daniel Shahaf
2019-12-17 10:02       ` zzapper
2019-12-17 10:14         ` Daniel Shahaf

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