zsh-users
 help / color / mirror / code / Atom feed
* problem with zmv
@ 2016-12-01 16:00 Ray Andrews
  2016-12-02 20:54 ` Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-01 16:00 UTC (permalink / raw)
  To: Zsh Users

Gentlemen:

'zmv' changes my prompt:

      4 /boot 4$ . zmv -C 'lilo.(????)-4' 'lilo.$1-5'
      ...
      $_tty $_blu/boot $_mag4$

I need to restart the shell to get it back.  Anything I can do about that?

BTW, I sent this yesterday and it came back as spam, so trying again.


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

* problem with zmv
  2016-12-01 16:00 problem with zmv Ray Andrews
@ 2016-12-02 20:54 ` Ray Andrews
  2016-12-02 21:15   ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-02 20:54 UTC (permalink / raw)
  To: Zsh Users

BTW, I sent this yesterday and it came back as spam, so trying again.

Third try:

Gentlemen:

'zmv' changes my prompt:

      4 /boot 4$ . zmv ...
      ...
      $_tty $_blu/boot $_mag4$

I need to restart the shell to get it back.

Here's my prompt:

     PS1=$'\n$_tty $_blu%d $_mag%L%{\e[0m%}$ %{\e[0m%}'

... so the above is taking things literally.  For example, '$_blu' is 
set as:

     _blu=$'%{\e[1;34m%}'

Anything I can do about that? zmv is the only function I've yet seen that does this.



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

* Re: problem with zmv
  2016-12-02 20:54 ` Ray Andrews
@ 2016-12-02 21:15   ` Bart Schaefer
  2016-12-02 23:36     ` Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2016-12-02 21:15 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

You don't run zmv with "." -- it's intended to be either autoloaded or
run as a script i.e. in a subshell.  If you load it with "." then the
"emulate -LR zsh" at the top affects your entire shell, rather than
being local to the function.


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

* Re: problem with zmv
  2016-12-02 21:15   ` Bart Schaefer
@ 2016-12-02 23:36     ` Ray Andrews
  2016-12-02 23:47       ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-02 23:36 UTC (permalink / raw)
  To: zsh-users

On 12/02/2016 01:15 PM, Bart Schaefer wrote:
> You don't run zmv with "." -- it's intended to be either autoloaded or
> run as a script i.e. in a subshell.  If you load it with "." then the
> "emulate -LR zsh" at the top affects your entire shell, rather than
> being local to the function.
>
Yikes, bad memories of autoload, IIRC I was bashing my head against 
that. Time to try again more compliantly perhaps; my rebellious streak 
is almost gone. But, I just now commented out the 'emulate' line, and it 
seems to run fine.  Is that safe?


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

* Re: problem with zmv
  2016-12-02 23:36     ` Ray Andrews
@ 2016-12-02 23:47       ` Bart Schaefer
  2016-12-03  0:15         ` Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2016-12-02 23:47 UTC (permalink / raw)
  To: Ray Andrews, zsh-users

On Dec 2,  3:36pm, Ray Andrews wrote:
}
} I just now commented out the 'emulate' line, and it 
} seems to run fine.  Is that safe?

It's safe as long as your setopts are "close enough" to the default zsh
configuration plus extendedglob.  If you use any of the options such
as globassign or shwordsplit that are going to change certain command
line intepretations, then no, it's not safe.


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

* Re: problem with zmv
  2016-12-02 23:47       ` Bart Schaefer
@ 2016-12-03  0:15         ` Ray Andrews
  2016-12-03  0:49           ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-03  0:15 UTC (permalink / raw)
  To: zsh-users

On 12/02/2016 03:47 PM, Bart Schaefer wrote:
> On Dec 2,  3:36pm, Ray Andrews wrote:
> }
> } I just now commented out the 'emulate' line, and it
> } seems to run fine.  Is that safe?
>
> It's safe as long as your setopts are "close enough" to the default zsh
> configuration plus extendedglob.  If you use any of the options such
> as globassign or shwordsplit that are going to change certain command
> line intepretations, then no, it's not safe.
>
Thanks Bart.  No, I'm not that sort of person.  I'll leave it commented 
for now with a caution and throw myself at autoload again since that 
seems kosher.  BTW, don't I remember something to the effect of changing 
setopts but only for the duration of a given script?  If so, that sounds 
like a healthy way of doing it.


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

* Re: problem with zmv
  2016-12-03  0:15         ` Ray Andrews
@ 2016-12-03  0:49           ` Bart Schaefer
  2016-12-03  2:59             ` Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2016-12-03  0:49 UTC (permalink / raw)
  To: Ray Andrews, zsh-users

On Dec 2,  4:15pm, Ray Andrews wrote:
}
} BTW, don't I remember something to the effect of changing 
} setopts but only for the duration of a given script?  If so, that sounds 
} like a healthy way of doing it.

I'm not recalling what you might be thinking of here, but you can
certainly do this:

alias zmv='() { . zmv }'

That will load zmv from $path instead of $fpath and use function scope
for the "emulate -L".


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

* Re: problem with zmv
  2016-12-03  0:49           ` Bart Schaefer
@ 2016-12-03  2:59             ` Ray Andrews
  2016-12-03  3:51               ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-03  2:59 UTC (permalink / raw)
  To: zsh-users

On 12/02/2016 04:49 PM, Bart Schaefer wrote:
> On Dec 2,  4:15pm, Ray Andrews wrote:
> }
> } BTW, don't I remember something to the effect of changing
> } setopts but only for the duration of a given script?  If so, that sounds
> } like a healthy way of doing it.
>
> I'm not recalling what you might be thinking of here, but you can
> certainly do this:
>
> alias zmv='() { . zmv }'
>
> That will load zmv from $path instead of $fpath and use function scope
> for the "emulate -L".
>
Kewl.  Works as you say, avoids editing the script and any other 
complications or gotchas.  So the outer function call trumps the 
protocol for the plain script, that's good to know for any similar issue.


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

* Re: problem with zmv
  2016-12-03  2:59             ` Ray Andrews
@ 2016-12-03  3:51               ` Bart Schaefer
  2016-12-03  5:58                 ` Mikael Magnusson
  2016-12-03 15:44                 ` Ray Andrews
  0 siblings, 2 replies; 16+ messages in thread
From: Bart Schaefer @ 2016-12-03  3:51 UTC (permalink / raw)
  To: zsh-users

On Dec 2,  6:59pm, Ray Andrews wrote:
}
} > On Dec 2,  4:15pm, Ray Andrews wrote:
} >
} > alias zmv='() { . zmv }'
} >
} Kewl.

It occurs to me that it might be slightly better to use

    alias zmv='function { . zmv }'

In the unlikely event that the "zmv" alias gets expanded as the second
word on the line, you'll get an error instead of defining the first
word on the line as a function that calls zmv.


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

* Re: problem with zmv
  2016-12-03  3:51               ` Bart Schaefer
@ 2016-12-03  5:58                 ` Mikael Magnusson
  2016-12-03 16:05                   ` Ray Andrews
  2016-12-03 15:44                 ` Ray Andrews
  1 sibling, 1 reply; 16+ messages in thread
From: Mikael Magnusson @ 2016-12-03  5:58 UTC (permalink / raw)
  To: Zsh Users

On Sat, Dec 3, 2016 at 4:51 AM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Dec 2,  6:59pm, Ray Andrews wrote:
> }
> } > On Dec 2,  4:15pm, Ray Andrews wrote:
> } >
> } > alias zmv='() { . zmv }'
> } >
> } Kewl.
>
> It occurs to me that it might be slightly better to use
>
>     alias zmv='function { . zmv }'
>
> In the unlikely event that the "zmv" alias gets expanded as the second
> word on the line, you'll get an error instead of defining the first
> word on the line as a function that calls zmv.

I feel it's worth pointing out to any other readers that the actual
correct way to do this is to just have
    autoload zmv
in your .zshrc and you're set for life.

-- 
Mikael Magnusson


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

* Re: problem with zmv
  2016-12-03  3:51               ` Bart Schaefer
  2016-12-03  5:58                 ` Mikael Magnusson
@ 2016-12-03 15:44                 ` Ray Andrews
  2016-12-03 17:05                   ` Bart Schaefer
  1 sibling, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-03 15:44 UTC (permalink / raw)
  To: zsh-users

On 12/02/2016 07:51 PM, Bart Schaefer wrote:
> On Dec 2,  6:59pm, Ray Andrews wrote:
> }
> } > On Dec 2,  4:15pm, Ray Andrews wrote:
> } >
> } > alias zmv='() { . zmv }'
> } >
> } Kewl.
>
> It occurs to me that it might be slightly better to use
>
>      alias zmv='function { . zmv }'
>
> In the unlikely event that the "zmv" alias gets expanded as the second
> word on the line, you'll get an error instead of defining the first
> word on the line as a function that calls zmv.
Gotcha ... ok, thanks Bart, I'll not try to understand why, that's taken 
on faith.


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

* Re: problem with zmv
  2016-12-03  5:58                 ` Mikael Magnusson
@ 2016-12-03 16:05                   ` Ray Andrews
  0 siblings, 0 replies; 16+ messages in thread
From: Ray Andrews @ 2016-12-03 16:05 UTC (permalink / raw)
  To: zsh-users

On 12/02/2016 09:58 PM, Mikael Magnusson wrote:
> I feel it's worth pointing out to any other readers that the actual 
> correct way to do this is to just have autoload zmv in your .zshrc and 
> you're set for life. 

So it is.  I just got over my autophobia and did that and what was I 
afraid of?   I had the idea of moving  things that I use routinely out 
of the vast caverns of zsh as supplied and into a directory of things 
that are in active use and on the path, but maybe that's not the best 
idea.  Anyway, between autoload, and what Bart showed me, I can do it 
either way so I'm as happy as a clam.


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

* Re: problem with zmv
  2016-12-03 15:44                 ` Ray Andrews
@ 2016-12-03 17:05                   ` Bart Schaefer
  2016-12-03 23:45                     ` Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2016-12-03 17:05 UTC (permalink / raw)
  To: zsh-users

On Dec 3,  7:44am, Ray Andrews wrote:
}
} On 12/02/2016 07:51 PM, Bart Schaefer wrote:
} > It occurs to me that it might be slightly better to use
} >
} >      alias zmv='function { . zmv }'
} >
} Gotcha ... ok, thanks Bart, I'll not try to understand why, that's taken 
} on faith.

I was having trouble coming up with an example last night, but:

You may have noticed that "noglob" acts a bit like "command" in that
aliases are not expanded:

% alias foo='echo you typed'
% noglob foo *
zsh: command not found: foo

So suppose you want aliases expanded after noglob.  To do that, you
need:

% alias noglob='noglob '

(with the trailing space in the quotes).  Now:

% noglob foo *
you typed *
% 

However, if you have

% alias zmv='() { . zmv }'
% noglob zmv
% functions
noglob () {
        . zmv
}
% 

It's very unlikely this would happen because you'd probably put some
arguments after zmv and get a parse error, but if you replace () with
"function" then you get the parse error every time and no accidents.

If you want noglob with zmv you have to autoload the real function, as
there's no way to use precommand modifiers with an anonymous function.


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

* Re: problem with zmv
  2016-12-03 17:05                   ` Bart Schaefer
@ 2016-12-03 23:45                     ` Ray Andrews
  2016-12-04  6:25                       ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2016-12-03 23:45 UTC (permalink / raw)
  To: zsh-users

On 12/03/2016 09:05 AM, Bart Schaefer wrote:
> On Dec 3,  7:44am, Ray Andrews wrote:
> }
> } On 12/02/2016 07:51 PM, Bart Schaefer wrote:
> } > It occurs to me that it might be slightly better to use
> } >
> } >      alias zmv='function { . zmv }'
> } >
> } Gotcha ... ok, thanks Bart, I'll not try to understand why, that's taken
> } on faith.
>
> I was having trouble coming up with an example last night, but:
>
> You may have noticed that "noglob" acts a bit like "command" in that
> aliases are not expanded:

I had no idea.  If ever I run into that, I'm warned in advance.
>
> % alias noglob='noglob '
>

I will never understand the thinking that produced things like that.

> If you want noglob with zmv you have to autoload the real function, as
> there's no way to use precommand modifiers with an anonymous function.
>
Ok, autoload it is.  Astonishing that you can remember all these little 
twists and turns Bart.  Simplicity is not a zsh virtue.


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

* Re: problem with zmv
  2016-12-03 23:45                     ` Ray Andrews
@ 2016-12-04  6:25                       ` Bart Schaefer
  2016-12-04 16:41                         ` Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2016-12-04  6:25 UTC (permalink / raw)
  To: zsh-users

On Dec 3,  3:45pm, Ray Andrews wrote:
}
} > % alias noglob='noglob '
} 
} I will never understand the thinking that produced things like that.

No one explicitly thought of that.  It's emergent behavior resulting
from other independent decisions.

} Astonishing that you can remember all these little 
} twists and turns Bart.

More often it's that I work them out all over again when somebody asks
a related question.


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

* Re: problem with zmv
  2016-12-04  6:25                       ` Bart Schaefer
@ 2016-12-04 16:41                         ` Ray Andrews
  0 siblings, 0 replies; 16+ messages in thread
From: Ray Andrews @ 2016-12-04 16:41 UTC (permalink / raw)
  To: zsh-users

On 12/03/2016 10:25 PM, Bart Schaefer wrote:
> On Dec 3,  3:45pm, Ray Andrews wrote:
> }
> } > % alias noglob='noglob '
> }
> } I will never understand the thinking that produced things like that.
>
> No one explicitly thought of that.  It's emergent behavior resulting
> from other independent decisions.

Not to get philosophical, but when things get too complicated ... but of 
course you don't need to hear it from me.


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

end of thread, other threads:[~2016-12-04 16:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-01 16:00 problem with zmv Ray Andrews
2016-12-02 20:54 ` Ray Andrews
2016-12-02 21:15   ` Bart Schaefer
2016-12-02 23:36     ` Ray Andrews
2016-12-02 23:47       ` Bart Schaefer
2016-12-03  0:15         ` Ray Andrews
2016-12-03  0:49           ` Bart Schaefer
2016-12-03  2:59             ` Ray Andrews
2016-12-03  3:51               ` Bart Schaefer
2016-12-03  5:58                 ` Mikael Magnusson
2016-12-03 16:05                   ` Ray Andrews
2016-12-03 15:44                 ` Ray Andrews
2016-12-03 17:05                   ` Bart Schaefer
2016-12-03 23:45                     ` Ray Andrews
2016-12-04  6:25                       ` Bart Schaefer
2016-12-04 16:41                         ` Ray Andrews

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