zsh-users
 help / color / mirror / code / Atom feed
* Two simple questions
@ 2004-09-13 15:52 Tero Niemela
  2004-09-13 18:57 ` Björn Lindström
  2004-09-13 21:10 ` DervishD
  0 siblings, 2 replies; 10+ messages in thread
From: Tero Niemela @ 2004-09-13 15:52 UTC (permalink / raw)
  To: zsh-users

Hi, I'd like to ask two questions that should be easy
to answer although with google I could not find
anything.

0) I'm seeing dirs like /bin /bin/ and even /bin// in
my PATH. What would be the best way to clean up the
trailing slashes? "typeset -U path" won't clean up
paths if they have different number of trailing
slashes (I mean all those mentioned paths are left but
other instances of, e.g., /bin are of course cleaned).

1) I use cygwin+zsh and it works great. I have in my
windows explorer "Command prompt here" option that
starts cmd.exe in the selected directory (with
"cmd.exe /k 'cd %1'" or something). How could I define
a command in command line that gets executed after all
zsh configuration files? zsh && cd /some/path of
course doesn't work.

Thanks for your help.


		
_______________________________
Do you Yahoo!?
Shop for Back-to-School deals on Yahoo! Shopping.
http://shopping.yahoo.com/backtoschool


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

* Re: Two simple questions
  2004-09-13 15:52 Two simple questions Tero Niemela
@ 2004-09-13 18:57 ` Björn Lindström
  2004-09-13 21:10 ` DervishD
  1 sibling, 0 replies; 10+ messages in thread
From: Björn Lindström @ 2004-09-13 18:57 UTC (permalink / raw)
  To: zsh-users

Tero Niemela <tero_niemela@yahoo.com> writes:

> I'm seeing dirs like /bin /bin/ and even /bin// in my PATH. What would
> be the best way to clean up the trailing slashes? "typeset -U path"
> won't clean up paths if they have different number of trailing slashes
> (I mean all those mentioned paths are left but other instances of,
> e.g., /bin are of course cleaned).

AFAIK, zsh never adds stuff to the path by itself with a trailing path -
so just stopping to do that yourself in your own config files, should
do the trick.

If this doesn't help you, you'll just have to write your own function
that normalises the paths - stripping the trailing slashes should be
easy enough - typeset wont do that for you.


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

* Re: Two simple questions
  2004-09-13 15:52 Two simple questions Tero Niemela
  2004-09-13 18:57 ` Björn Lindström
@ 2004-09-13 21:10 ` DervishD
  2004-09-14 16:37   ` Tero Niemela
  1 sibling, 1 reply; 10+ messages in thread
From: DervishD @ 2004-09-13 21:10 UTC (permalink / raw)
  To: Tero Niemela; +Cc: zsh-users

    Hi Tero :)

 * Tero Niemela <tero_niemela@yahoo.com> dixit:
> 0) I'm seeing dirs like /bin /bin/ and even /bin// in
> my PATH. What would be the best way to clean up the
> trailing slashes? "typeset -U path" won't clean up
> paths if they have different number of trailing
> slashes (I mean all those mentioned paths are left but
> other instances of, e.g., /bin are of course cleaned).

    'typeset -U' just 'uniqize', it doesn't normalize. You're looking
for something like (EXTENDED_GLOB must be set, for the '#'):

    path=(${(qq)${path//\/##/\/}%/})

    This converts multiple slashes to just one, and then removes the
last one. The '(qq)' part is needed just in case 'path' has elements
with spaces in it.

> 1) I use cygwin+zsh and it works great. I have in my
> windows explorer "Command prompt here" option that
> starts cmd.exe in the selected directory (with
> "cmd.exe /k 'cd %1'" or something). How could I define
> a command in command line that gets executed after all
> zsh configuration files? zsh && cd /some/path of
> course doesn't work.

    Just add that command at the end of the last config file read. If
the shell is interactive, try /etc/zshrc (well, I don't know which
name it has under cygwin, sorry).

    Hope that helps :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Two simple questions
  2004-09-13 21:10 ` DervishD
@ 2004-09-14 16:37   ` Tero Niemela
  2004-09-14 17:19     ` DervishD
  0 siblings, 1 reply; 10+ messages in thread
From: Tero Niemela @ 2004-09-14 16:37 UTC (permalink / raw)
  To: zsh-users

Hi!

> > 0) I'm seeing dirs like /bin /bin/ and even /bin//
> in
> > my PATH.
> 
> You're looking
> for something like (EXTENDED_GLOB must be set, for
> the '#'):
> 
>     path=(${(qq)${path//\/##/\/}%/})
> 
>     This converts multiple slashes to just one, and
> then removes the
> last one. The '(qq)' part is needed just in case
> 'path' has elements with spaces in it.

In some cases (Cygwin) it indeed does have spaces.
However, your solution seems not to be optiomal:

~> export PATH=/bin:/usr/bin:/bin//:/bin/
~> which ls                              
/bin/ls
~> path=(${(qq)${path//\/##/\/}%/})
~> echo $PATH
'/bin':'/usr/bin':'/bin/'
~> which ls
ls not found
zsh: exit 1
~> 

> > 1) I use cygwin+zsh and it works great. I have in
> my
> > windows explorer "Command prompt here" option that
> > starts cmd.exe in the selected directory (with
> > "cmd.exe /k 'cd %1'" or something). How could I
> define
> > a command in command line that gets executed after
> all
> > zsh configuration files? zsh && cd /some/path of
> > course doesn't work.
> 
>     Just add that command at the end of the last
> config file read.

I did the following, works perfectly for me:

Last line of ~/.zlogin is:

[[ "$OSTYPE" = *cygwin* && $ARGC -eq 1 ]] && cd "$@"

And this registry settings was added to Windows
registry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\command]
@="Cygwin Here"

[HKEY_CLASSES_ROOT\Folder\shell\command\command]
@="\"C:\\cygwin\\bin\\zsh.exe\" -l -s \"%1\""

Thanks!


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 


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

* Re: Two simple questions
  2004-09-14 16:37   ` Tero Niemela
@ 2004-09-14 17:19     ` DervishD
  2004-09-14 18:55       ` Tero Niemela
  0 siblings, 1 reply; 10+ messages in thread
From: DervishD @ 2004-09-14 17:19 UTC (permalink / raw)
  To: Tero Niemela; +Cc: zsh-users

    Hi Tero :)

 * Tero Niemela <tero_niemela@yahoo.com> dixit:
> > > 0) I'm seeing dirs like /bin /bin/ and even /bin//
> > in
> > > my PATH.
> > You're looking
> > for something like (EXTENDED_GLOB must be set, for
> > the '#'):
> >     path=(${(qq)${path//\/##/\/}%/})
> > 
> >     This converts multiple slashes to just one, and
> > then removes the
> > last one. The '(qq)' part is needed just in case
> > 'path' has elements with spaces in it.
> In some cases (Cygwin) it indeed does have spaces.
> However, your solution seems not to be optiomal:
> ~> export PATH=/bin:/usr/bin:/bin//:/bin/
> ~> which ls                              
> /bin/ls
> ~> path=(${(qq)${path//\/##/\/}%/})
> ~> echo $PATH
> '/bin':'/usr/bin':'/bin/'
> ~> which ls
> ls not found
> zsh: exit 1
> ~> 

    The slash removing works here. It seems you don't have
'EXTENDED_GLOB' set. You must in order the recipe to work ;)

    And yes, the quoting completely screws the functioning of the
PATH, and the worst thing is that... it is not needed O:) Array
elements are separate words, so you just need to do this:

    setopt EXTENDED_GLOB
    path=(${${path//\/##/\/}%/})
    unsetopt EXTENDED_GLOB

    The setopt is only needed, obviously, if you don't have
EXTENDED_GLOB set, which you don't seem to have.

    Hope this helps :) At least it works for me with your example
above (and adding a directory with spaces in it.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Two simple questions
  2004-09-14 17:19     ` DervishD
@ 2004-09-14 18:55       ` Tero Niemela
  2004-09-14 19:09         ` DervishD
  0 siblings, 1 reply; 10+ messages in thread
From: Tero Niemela @ 2004-09-14 18:55 UTC (permalink / raw)
  To: zsh-users

Hi!

> so you just need to do this:
> 
>     setopt EXTENDED_GLOB
>     path=(${${path//\/##/\/}%/})
>     unsetopt EXTENDED_GLOB

Thanks! This works all ok here, too. For reference, my
ultimate path cleaning now contains:

# Clean up paths 
path=($^path(N))
manpath=($^manpath(N)) 
setopt EXTENDED_GLOB
path=(${${path//\/##/\/}%/})
manpath=(${${manpath//\/##/\/}%/})
unsetopt EXTENDED_GLOB  
typeset -U path manpath



		
__________________________________
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now. 
http://messenger.yahoo.com


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

* Re: Two simple questions
  2004-09-14 18:55       ` Tero Niemela
@ 2004-09-14 19:09         ` DervishD
  2004-09-15  5:11           ` Tero Niemela
  0 siblings, 1 reply; 10+ messages in thread
From: DervishD @ 2004-09-14 19:09 UTC (permalink / raw)
  To: Tero Niemela; +Cc: zsh-users

    Hi Tero :)

> Thanks! This works all ok here, too. For reference, my
> ultimate path cleaning now contains:
> 
> # Clean up paths 
> path=($^path(N))
> manpath=($^manpath(N)) 

    I don't get that two. The 'N' sets nullglob for that expansion,
right but, why the '^'? AFAIK that only turns on 'RC_EXPAND_PARAM'
for that expansion :? I'm curious :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Two simple questions
  2004-09-14 19:09         ` DervishD
@ 2004-09-15  5:11           ` Tero Niemela
  2004-09-15  8:36             ` DervishD
  0 siblings, 1 reply; 10+ messages in thread
From: Tero Niemela @ 2004-09-15  5:11 UTC (permalink / raw)
  To: zsh-users

Hi!

> > # Clean up paths 
> > path=($^path(N))
> > manpath=($^manpath(N)) 
> 
>     I don't get that two. The 'N' sets nullglob for
> that expansion,
> right but, why the '^'? AFAIK that only turns on
> 'RC_EXPAND_PARAM'
> for that expansion :? I'm curious :)

Those removes non-existing dirs from paths. It was
suggested on this list just a couple of months ago.
See for the explanation at:

http://www.zsh.org/mla/users/2004/msg00608.html


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


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

* Re: Two simple questions
  2004-09-15  5:11           ` Tero Niemela
@ 2004-09-15  8:36             ` DervishD
  2004-09-15 10:29               ` Stephane Chazelas
  0 siblings, 1 reply; 10+ messages in thread
From: DervishD @ 2004-09-15  8:36 UTC (permalink / raw)
  To: Tero Niemela; +Cc: zsh-users

    Hi Tero :)

 * Tero Niemela <tero_niemela@yahoo.com> dixit:
> > > # Clean up paths 
> > > path=($^path(N))
> > > manpath=($^manpath(N)) 
> >     I don't get that two. The 'N' sets nullglob for
> > that expansion,
> > right but, why the '^'? AFAIK that only turns on
> > 'RC_EXPAND_PARAM'
> > for that expansion :? I'm curious :)
> Those removes non-existing dirs from paths. It was
> suggested on this list just a couple of months ago.

    Very clever! :) The '^' makes the '(N)' glob qualifier to be
added to each element of the array :)) Thanks a lot for the
explanation, is a very clever way of removing non-existent dirs from
a list (well, an array in this case).

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Two simple questions
  2004-09-15  8:36             ` DervishD
@ 2004-09-15 10:29               ` Stephane Chazelas
  0 siblings, 0 replies; 10+ messages in thread
From: Stephane Chazelas @ 2004-09-15 10:29 UTC (permalink / raw)
  To: zsh-users; +Cc: Tero Niemela

On Wed, Sep 15, 2004 at 10:36:56AM +0200, DervishD wrote:
[...]
> > > > path=($^path(N))
> > > > manpath=($^manpath(N)) 
[...]
>     Very clever! :) The '^' makes the '(N)' glob qualifier to be
> added to each element of the array :)) Thanks a lot for the
> explanation, is a very clever way of removing non-existent dirs from
> a list (well, an array in this case).
[...]

All the given solutions seem to forget about one thing about
$PATH. An empty element in it means "current directory".

$path instead of "$path[@]" removes the empty components in it.
That doesn't apply to $^path, though, but to the other
solutions.

$ echo $PATH
/usr/xpg4/bin:/usr/bin:/usr/local/bin:
$ print -rl $path
/usr/xpg4/bin
/usr/bin
/usr/local/bin
$ print -rl "$path[@]"
/usr/xpg4/bin
/usr/bin
/usr/local/bin

$ print -rl ${^path}(N)
/usr/xpg4/bin
/usr/bin
/usr/local/bin
$ 

You can change "" to "." with ${path/(#s)(#e)/.}
but that's slightly different.

$ PATH=/::/bin://bin/
$ print -rl ${(u)${${path/(#s)(#e)/.}//\/##/\/}/(#b)(?)\/(#e)/$match}
/
.
/bin
$ 

(note that ${path/%\//} changes "/" into "".

-- 
Stephane


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

end of thread, other threads:[~2004-09-15 10:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-13 15:52 Two simple questions Tero Niemela
2004-09-13 18:57 ` Björn Lindström
2004-09-13 21:10 ` DervishD
2004-09-14 16:37   ` Tero Niemela
2004-09-14 17:19     ` DervishD
2004-09-14 18:55       ` Tero Niemela
2004-09-14 19:09         ` DervishD
2004-09-15  5:11           ` Tero Niemela
2004-09-15  8:36             ` DervishD
2004-09-15 10:29               ` Stephane Chazelas

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