zsh-users
 help / color / mirror / code / Atom feed
* Problem with user function
@ 2024-02-23 17:49 Duke Normandin
  2024-02-23 18:16 ` Ray Andrews
  2024-02-23 18:30 ` Roman Perepelitsa
  0 siblings, 2 replies; 19+ messages in thread
From: Duke Normandin @ 2024-02-23 17:49 UTC (permalink / raw)
  To: zsh-users list

After installing .oh-my-zsh, I get this error msg, which I didn't
while running plain zsh.

.zshrc:92: defining function based on alias `ls'
.zshrc:92: parse error near `()'

The errors refer to a few functions that I use to take notes:

n() {$EDITOR ~/notes/${1}.txt}
l() {$PAGER ~/notes/${1}.txt}
nls() {ls --group-directories-first -c --color ~/notes/${1} }

I would appreciate some help as I'm not a zsh hacker, but merely an
unsophisticated user. TIA ..
--
Duke


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

* Re: Problem with user function
  2024-02-23 17:49 Problem with user function Duke Normandin
@ 2024-02-23 18:16 ` Ray Andrews
  2024-02-23 18:31   ` Roman Perepelitsa
  2024-02-23 18:32   ` Bart Schaefer
  2024-02-23 18:30 ` Roman Perepelitsa
  1 sibling, 2 replies; 19+ messages in thread
From: Ray Andrews @ 2024-02-23 18:16 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]



On 2024-02-23 09:49, Duke Normandin wrote:
> .zshrc:92: defining function based on alias `ls'
> .zshrc:92: parse error near `()'
>
> nls() {ls --group-directories-first -c --color ~/notes/${1} }
>
You'll be getting better answers shortly, but for now:

You can't have an alias like that inside a function.  Somewhere 
oh-my-zsh has aliased 'ls' so you've either got to change that alias or 
do this:

nls() {/usr/bin/ls --group-directories-first -c --color ~/notes/${1} }

... so that the shell knows to use the binary command.

[-- Attachment #2: Type: text/html, Size: 971 bytes --]

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

* Re: Problem with user function
  2024-02-23 17:49 Problem with user function Duke Normandin
  2024-02-23 18:16 ` Ray Andrews
@ 2024-02-23 18:30 ` Roman Perepelitsa
  2024-02-23 18:35   ` Duke Normandin
  1 sibling, 1 reply; 19+ messages in thread
From: Roman Perepelitsa @ 2024-02-23 18:30 UTC (permalink / raw)
  To: Duke Normandin; +Cc: zsh-users list

On Fri, Feb 23, 2024 at 6:49 PM Duke Normandin <dukeofpurl@gmx.com> wrote:
>
> After installing .oh-my-zsh, I get this error msg, which I didn't
> while running plain zsh.
>
> .zshrc:92: defining function based on alias `ls'
> .zshrc:92: parse error near `()'
>
> The errors refer to a few functions that I use to take notes:
>
> n() {$EDITOR ~/notes/${1}.txt}
> l() {$PAGER ~/notes/${1}.txt}
> nls() {ls --group-directories-first -c --color ~/notes/${1} }

I don't see anything wrong with this code. The error you've got
happens when you do this:

    alias ls='ls -A'
    ls() { whatever; }

Does your .zshrc attempt to define a function called "ls" on line 92?
What does that line look like?

Roman.


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

* Re: Problem with user function
  2024-02-23 18:16 ` Ray Andrews
@ 2024-02-23 18:31   ` Roman Perepelitsa
  2024-02-23 18:36     ` Bart Schaefer
  2024-02-23 19:26     ` Ray Andrews
  2024-02-23 18:32   ` Bart Schaefer
  1 sibling, 2 replies; 19+ messages in thread
From: Roman Perepelitsa @ 2024-02-23 18:31 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Fri, Feb 23, 2024 at 7:16 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> On 2024-02-23 09:49, Duke Normandin wrote:
>
> nls() {ls --group-directories-first -c --color ~/notes/${1} }
>
> You'll be getting better answers shortly, but for now:
>
> You can't have an alias like that inside a function.

You can. Try it.

Roman.


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

* Re: Problem with user function
  2024-02-23 18:16 ` Ray Andrews
  2024-02-23 18:31   ` Roman Perepelitsa
@ 2024-02-23 18:32   ` Bart Schaefer
  2024-02-23 18:52     ` Ray Andrews
  1 sibling, 1 reply; 19+ messages in thread
From: Bart Schaefer @ 2024-02-23 18:32 UTC (permalink / raw)
  To: zsh-users

Close, Ray, but not quite.

On Fri, Feb 23, 2024 at 10:16 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> On 2024-02-23 09:49, Duke Normandin wrote:
>
> > .zshrc:92: defining function based on alias `ls'

That message means that the thing on the LEFT side of the empty parens
() refers to an alias, not that something inside the function does.

> > .zshrc:92: parse error near `()'

And that one means that whatever the alias expanded into, was not a
syntactically valid function name, so it can't have () after it.

> Somewhere oh-my-zsh has aliased 'ls'

That part you got right.  Generally speaking any inquiry that begins
with "After installing .oh-my-zsh," should be directed to an oh-my-zsh
forum before coming here.


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

* Re: Problem with user function
  2024-02-23 18:30 ` Roman Perepelitsa
@ 2024-02-23 18:35   ` Duke Normandin
  2024-02-23 18:50     ` Duke Normandin
  2024-02-23 18:52     ` Roman Perepelitsa
  0 siblings, 2 replies; 19+ messages in thread
From: Duke Normandin @ 2024-02-23 18:35 UTC (permalink / raw)
  To: zsh-users

On Fri, 23 Feb 2024 19:30:15 +0100
Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:

> On Fri, Feb 23, 2024 at 6:49 PM Duke Normandin
> <dukeofpurl@gmx.com> wrote:
> >
> > After installing .oh-my-zsh, I get this error msg, which I
> > didn't while running plain zsh.
> >
> > .zshrc:92: defining function based on alias `ls'
> > .zshrc:92: parse error near `()'
> >
> > The errors refer to a few functions that I use to take notes:
> >
> > n() {$EDITOR ~/notes/${1}.txt}
> > l() {$PAGER ~/notes/${1}.txt}
> > nls() {ls --group-directories-first -c --color ~/notes/${1} }
>
> I don't see anything wrong with this code. The error you've got
> happens when you do this:
>
>     alias ls='ls -A'
>     ls() { whatever; }

No! It happens when I launch a terminal and my .zshrc file is read.

> Does your .zshrc attempt to define a function called "ls" on line
> 92? What does that line look like?

It looks like what I included in my original message. See above in
the quotes!
--
Duke


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

* Re: Problem with user function
  2024-02-23 18:31   ` Roman Perepelitsa
@ 2024-02-23 18:36     ` Bart Schaefer
  2024-02-23 19:26     ` Ray Andrews
  1 sibling, 0 replies; 19+ messages in thread
From: Bart Schaefer @ 2024-02-23 18:36 UTC (permalink / raw)
  To: zsh-users

On Fri, Feb 23, 2024 at 10:32 AM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> On Fri, Feb 23, 2024 at 7:16 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
> >
> > You can't have an alias like that inside a function.
>
> You can. Try it.

Ray is confusing the error message, with the difference between this:

alias ls='ls -A'
nls() { ls ~/notes/${1} }

And this:

nls() { ls ~/notes/${1} }
alias ls='ls -A'

In the latter example, "nls" will not use the alias, whereas in the
former example, it will.

Zsh does not issue a warning for either of those examples, though.


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

* Re: Problem with user function
  2024-02-23 18:35   ` Duke Normandin
@ 2024-02-23 18:50     ` Duke Normandin
  2024-02-23 18:52     ` Roman Perepelitsa
  1 sibling, 0 replies; 19+ messages in thread
From: Duke Normandin @ 2024-02-23 18:50 UTC (permalink / raw)
  To: zsh-users list

On Fri, 23 Feb 2024 11:35:50 -0700
Duke Normandin <dukeofpurl@gmx.com> wrote:

> On Fri, 23 Feb 2024 19:30:15 +0100
> Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
>
> > On Fri, Feb 23, 2024 at 6:49 PM Duke Normandin
> > <dukeofpurl@gmx.com> wrote:
> > >
> > > After installing .oh-my-zsh, I get this error msg, which I
> > > didn't while running plain zsh.
> > >
> > > .zshrc:92: defining function based on alias `ls'
> > > .zshrc:92: parse error near `()'
> > >
> > > The errors refer to a few functions that I use to take notes:
> > >
> > > n() {$EDITOR ~/notes/${1}.txt}
> > > l() {$PAGER ~/notes/${1}.txt}
> > > nls() {ls --group-directories-first -c --color ~/notes/${1} }
> >
> > I don't see anything wrong with this code. The error you've got
> > happens when you do this:
> >
> >     alias ls='ls -A'
> >     ls() { whatever; }
>
> No! It happens when I launch a terminal and my .zshrc file is
> read.
>
> > Does your .zshrc attempt to define a function called "ls" on
> > line 92? What does that line look like?
>
> It looks like what I included in my original message. See above in
> the quotes!
> --
> Duke

I fixed the problem by appending `function' before the function
names. The problem went away!
--
Duke


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

* Re: Problem with user function
  2024-02-23 18:32   ` Bart Schaefer
@ 2024-02-23 18:52     ` Ray Andrews
  0 siblings, 0 replies; 19+ messages in thread
From: Ray Andrews @ 2024-02-23 18:52 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]



On 2024-02-23 10:32, Bart Schaefer wrote:
> Close, Ray, but not quite.
>
> That message means that the thing on the LEFT side of the empty parens
> () refers to an alias, not that something inside the function does.
I knew you guys would correct any errors, I was just taking a first stab 
at it.

And that one means that whatever the alias expanded into, was not a
> syntactically valid function name, so it can't have () after it.
Right!
> That part you got right.  Generally speaking any inquiry that begins
> with "After installing .oh-my-zsh," should be directed to an oh-my-zsh
> forum before coming here.
Let's be kind to the Prodigal Sons, returning from the fleshpots of 
oh-my-zsh.


[-- Attachment #2: Type: text/html, Size: 1560 bytes --]

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

* Re: Problem with user function
  2024-02-23 18:35   ` Duke Normandin
  2024-02-23 18:50     ` Duke Normandin
@ 2024-02-23 18:52     ` Roman Perepelitsa
  2024-02-23 18:56       ` Duke Normandin
  1 sibling, 1 reply; 19+ messages in thread
From: Roman Perepelitsa @ 2024-02-23 18:52 UTC (permalink / raw)
  To: Duke Normandin; +Cc: zsh-users

On Fri, Feb 23, 2024 at 7:36 PM Duke Normandin <dukeofpurl@gmx.com> wrote:
>
> On Fri, 23 Feb 2024 19:30:15 +0100
> Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
>>
> > I don't see anything wrong with this code. The error you've got
> > happens when you do this:
> >
> >     alias ls='ls -A'
> >     ls() { whatever; }
>
> No! It happens when I launch a terminal and my .zshrc file is read.

Let me rephrase that: you'll get the same error by running *those* commands.

> > Does your .zshrc attempt to define a function called "ls" on line
> > 92? What does that line look like?
>
> It looks like what I included in my original message. See above in
> the quotes!

What is the output of the following command?

zsh -ic 'print -r -- ${"${(f)$(<${ZDOTDIR:-$HOME}/.zshrc)}"[92]}'

Roman.


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

* Re: Problem with user function
  2024-02-23 18:52     ` Roman Perepelitsa
@ 2024-02-23 18:56       ` Duke Normandin
  2024-02-23 19:00         ` Roman Perepelitsa
  0 siblings, 1 reply; 19+ messages in thread
From: Duke Normandin @ 2024-02-23 18:56 UTC (permalink / raw)
  To: zsh-users list

On Fri, 23 Feb 2024 19:52:26 +0100
Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:

> zsh -ic 'print -r -- ${"${(f)$(<${ZDOTDIR:-$HOME}/.zshrc)}"[92]}'

Nothing! A blank line.
BUT - the problem is fixed! :) Thx...
--
Duke


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

* Re: Problem with user function
  2024-02-23 18:56       ` Duke Normandin
@ 2024-02-23 19:00         ` Roman Perepelitsa
  0 siblings, 0 replies; 19+ messages in thread
From: Roman Perepelitsa @ 2024-02-23 19:00 UTC (permalink / raw)
  To: Duke Normandin; +Cc: zsh-users list

On Fri, Feb 23, 2024 at 7:57 PM Duke Normandin <dukeofpurl@gmx.com> wrote:
>
> On Fri, 23 Feb 2024 19:52:26 +0100
> Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
>
> > zsh -ic 'print -r -- ${"${(f)$(<${ZDOTDIR:-$HOME}/.zshrc)}"[92]}'
>
> Nothing! A blank line.

I guess I should've been explicit about running the command with the
original content of .zshrc.

> BUT - the problem is fixed! :) Thx...

I am glad.



Roman.


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

* Re: Problem with user function
  2024-02-23 18:31   ` Roman Perepelitsa
  2024-02-23 18:36     ` Bart Schaefer
@ 2024-02-23 19:26     ` Ray Andrews
  2024-02-23 19:40       ` Roman Perepelitsa
  2024-02-23 20:34       ` Bart Schaefer
  1 sibling, 2 replies; 19+ messages in thread
From: Ray Andrews @ 2024-02-23 19:26 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]



On 2024-02-23 10:31, Roman Perepelitsa wrote:
>> You can't have an alias like that inside a function.
> You can. Try it.
This is basically a dead issue now, but trying it is exactly what I did:


% alias X='echo howdy'; Y() { X }
zsh: defining function based on alias `Y'
zsh: parse error near `()'

... but maybe that's not exactly the same thing.  I just noticed the 
same messages.

BTW, interesting that his problem was solved by adding 'function' -- I 
though that was always optional, but in this case the parser seems to care.

=======================================


>
> Roman.
>

[-- Attachment #2: Type: text/html, Size: 1431 bytes --]

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

* Re: Problem with user function
  2024-02-23 19:26     ` Ray Andrews
@ 2024-02-23 19:40       ` Roman Perepelitsa
  2024-02-23 19:59         ` Ray Andrews
  2024-02-23 20:34       ` Bart Schaefer
  1 sibling, 1 reply; 19+ messages in thread
From: Roman Perepelitsa @ 2024-02-23 19:40 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Fri, Feb 23, 2024 at 8:26 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> This is basically a dead issue now, but trying it is exactly what I did:
>
>
> % alias X='echo howdy'; Y() { X }
> zsh: defining function based on alias `Y'
> zsh: parse error near `()'

Can you reproduce this by running the command within `zsh -f`? Recall
that `zsh -f` gives you a blank state: zsh with no rc files sourced.

> BTW, interesting that his problem was solved by adding 'function' -- I though that was always optional, but in this case the parser seems to care.

Non-global aliases are expanded only in command position, so adding
`function` in front of `ls()`  disables alias expansion of `ls` and
thus fixes the problem Duke was having.

Roman.


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

* Re: Problem with user function
  2024-02-23 19:40       ` Roman Perepelitsa
@ 2024-02-23 19:59         ` Ray Andrews
  2024-02-23 20:05           ` Roman Perepelitsa
  2024-02-23 20:27           ` Bart Schaefer
  0 siblings, 2 replies; 19+ messages in thread
From: Ray Andrews @ 2024-02-23 19:59 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]



On 2024-02-23 11:40, Roman Perepelitsa wrote:

> % alias X='echo howdy'; Y() { X }
>> zsh: defining function based on alias `Y'
>> zsh: parse error near `()'
> Can you reproduce this by running the command within `zsh -f`? Recall
> that `zsh -f` gives you a blank state: zsh with no rc files sourced.
No error:

0 /aRay 0 % zsh -f
b6-12-Deb11b#  alias X='echo howdy'; Y () { X }
b6-12-Deb11b#

... nuts, I wonder if I've presumed a 'rule' that isn't a rule at all, 
just some artifact of my configuration?  I'm in the mood to let sleeping 
dogs lie, but still ...

And then there's this and I probably don't want to know:

0 /aRay 0 % zsh -f
b6-12-Deb11b#  alias X='echo howdy'; Y () { X }
b6-12-Deb11b# Y
(EE)
Fatal server error:
(EE) Server is already active for display 0
     If this server is no longer running, remove /tmp/.X0-lock
     and start again.
(EE)
(EE)
Please consult the The X.Org Foundation support
      at http://wiki.x.org
  for help.
(EE)
b6-12-Deb11b#

... I don't want to know.  It is not given to morals to understand what 
X does.


[-- Attachment #2: Type: text/html, Size: 1918 bytes --]

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

* Re: Problem with user function
  2024-02-23 19:59         ` Ray Andrews
@ 2024-02-23 20:05           ` Roman Perepelitsa
  2024-02-23 20:27           ` Bart Schaefer
  1 sibling, 0 replies; 19+ messages in thread
From: Roman Perepelitsa @ 2024-02-23 20:05 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Fri, Feb 23, 2024 at 8:59 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> 0 /aRay 0 % zsh -f
> b6-12-Deb11b#  alias X='echo howdy'; Y () { X }
> b6-12-Deb11b# Y
> (EE)
> Fatal server error:

You'll get the same results by running `zsh -f` and then `X`.

You would get a different result if you ran `alias X='echo howdy'` and
`Y () { X }` separately. In this case `X` would get expanded within
`Y()`.

Roman.


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

* Re: Problem with user function
  2024-02-23 19:59         ` Ray Andrews
  2024-02-23 20:05           ` Roman Perepelitsa
@ 2024-02-23 20:27           ` Bart Schaefer
  1 sibling, 0 replies; 19+ messages in thread
From: Bart Schaefer @ 2024-02-23 20:27 UTC (permalink / raw)
  To: zsh-users

On Fri, Feb 23, 2024 at 11:59 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> b6-12-Deb11b#  alias X='echo howdy'; Y () { X }

This isn't a valid test anyway, because you can't create an alias on
the left side of a ";" and then use it on the right side -- there has
to be a newline (and e.g. a new prompt) in between definition and
usage of aliases.


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

* Re: Problem with user function
  2024-02-23 19:26     ` Ray Andrews
  2024-02-23 19:40       ` Roman Perepelitsa
@ 2024-02-23 20:34       ` Bart Schaefer
  2024-02-23 20:46         ` Ray Andrews
  1 sibling, 1 reply; 19+ messages in thread
From: Bart Schaefer @ 2024-02-23 20:34 UTC (permalink / raw)
  To: Zsh Users

On Fri, Feb 23, 2024 at 11:26 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> % alias X='echo howdy'; Y() { X }
> zsh: defining function based on alias `Y'

Aside from the "not a valid test" thing, note that it said "based on
alias `Y'" but the alias you tried to create was for X.

There must already be an "alias Y=..." (for some "...") at the time
you ran this.


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

* Re: Problem with user function
  2024-02-23 20:34       ` Bart Schaefer
@ 2024-02-23 20:46         ` Ray Andrews
  0 siblings, 0 replies; 19+ messages in thread
From: Ray Andrews @ 2024-02-23 20:46 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 425 bytes --]


On 2024-02-23 12:34, Bart Schaefer wrote:
> There must already be an "alias Y=..." (for some "...") at the time
> you ran this.
Right!  Hardly use it.  Forgot that it was there.  Gotta use 'zsh -f' 
more often just to be sure I'm running uncontaminated tests. Issues like 
this are just noise, they should not arise.  I wish I could go back in 
the archives and delete stuff like this that has zero reason to exist.





[-- Attachment #2: Type: text/html, Size: 1088 bytes --]

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

end of thread, other threads:[~2024-02-23 20:50 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 17:49 Problem with user function Duke Normandin
2024-02-23 18:16 ` Ray Andrews
2024-02-23 18:31   ` Roman Perepelitsa
2024-02-23 18:36     ` Bart Schaefer
2024-02-23 19:26     ` Ray Andrews
2024-02-23 19:40       ` Roman Perepelitsa
2024-02-23 19:59         ` Ray Andrews
2024-02-23 20:05           ` Roman Perepelitsa
2024-02-23 20:27           ` Bart Schaefer
2024-02-23 20:34       ` Bart Schaefer
2024-02-23 20:46         ` Ray Andrews
2024-02-23 18:32   ` Bart Schaefer
2024-02-23 18:52     ` Ray Andrews
2024-02-23 18:30 ` Roman Perepelitsa
2024-02-23 18:35   ` Duke Normandin
2024-02-23 18:50     ` Duke Normandin
2024-02-23 18:52     ` Roman Perepelitsa
2024-02-23 18:56       ` Duke Normandin
2024-02-23 19:00         ` Roman Perepelitsa

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