zsh-users
 help / color / mirror / code / Atom feed
* Named directories
@ 2005-02-21 14:17 Mika Seppänen
  2005-02-21 14:21 ` Vincent Lefevre
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Mika Seppänen @ 2005-02-21 14:17 UTC (permalink / raw)
  To: zsh-users

Hi all,

If my homedir is /home/foo and I have named directory:

work=/home/foo/bar

Then if I switch to that dir (cd work), %~ expands to ~/bar. Is there 
any way to make it expand to ~work?

Thanks,
Mika Seppänen

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

* Re: Named directories
  2005-02-21 14:17 Named directories Mika Seppänen
@ 2005-02-21 14:21 ` Vincent Lefevre
  2005-02-21 14:31 ` Peter Stephenson
  2005-02-26 22:17 ` Bart Schaefer
  2 siblings, 0 replies; 11+ messages in thread
From: Vincent Lefevre @ 2005-02-21 14:21 UTC (permalink / raw)
  To: zsh-users

On 2005-02-21 16:17:13 +0200, Mika Seppänen wrote:
> If my homedir is /home/foo and I have named directory:
> 
> work=/home/foo/bar
> 
> Then if I switch to that dir (cd work), %~ expands to ~/bar. Is there 
> any way to make it expand to ~work?

I have so such problem here:

ay:~> echo ~ ~tmp
/home/lefevre /home/lefevre/tmp
ay:~> cd tmp
ay:~tmp>

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA


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

* Re: Named directories
  2005-02-21 14:17 Named directories Mika Seppänen
  2005-02-21 14:21 ` Vincent Lefevre
@ 2005-02-21 14:31 ` Peter Stephenson
  2005-02-21 14:51   ` Mika Seppänen
  2005-02-26 22:17 ` Bart Schaefer
  2 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2005-02-21 14:31 UTC (permalink / raw)
  To: zsh-users

=?ISO-8859-1?Q?Mika_Sepp=E4nen?= wrote:
> Hi all,
> 
> If my homedir is /home/foo and I have named directory:
> 
> work=/home/foo/bar
> 
> Then if I switch to that dir (cd work), %~ expands to ~/bar. Is there
> any way to make it expand to ~work?

You need to refer to "~work" at least once; the usual trick is to put

: ~work

in your .zshrc after defining the directory.  You can also "setopt
autonamedirs" to make all such parameters eligible for this
replacement.

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


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

* Re: Named directories
  2005-02-21 14:31 ` Peter Stephenson
@ 2005-02-21 14:51   ` Mika Seppänen
  2005-02-21 21:49     ` Mika Seppänen
  2005-02-22  4:35     ` Seth Kurtzberg
  0 siblings, 2 replies; 11+ messages in thread
From: Mika Seppänen @ 2005-02-21 14:51 UTC (permalink / raw)
  To: zsh-users

21.2.2005 kello 16:31, Peter Stephenson wrote:

> You need to refer to "~work" at least once; the usual trick is to put
>
> : ~work
>
> in your .zshrc after defining the directory.  You can also "setopt
> autonamedirs" to make all such parameters eligible for this
> replacement.

I found that by reading manuals and using google, but It doesn't help.

I get following: (PS1=%s\> and option autonamedirs unset, though seting 
it doesn't change situation in anyway)

~>cd work
~/Projektit/rnd/ott/sip.imp
~/Projektit/rnd/ott/sip.imp>pwd
/Users/c8z/Projektit/rnd/ott/sip.imp
~/Projektit/rnd/ott/sip.imp>cd foo
~foo
~foo>pwd
/usr/local/etc
~foo>

(zsh 4.1.1 on Mac OS X)

Mika


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

* Re: Named directories
  2005-02-21 14:51   ` Mika Seppänen
@ 2005-02-21 21:49     ` Mika Seppänen
  2005-02-22  4:35     ` Seth Kurtzberg
  1 sibling, 0 replies; 11+ messages in thread
From: Mika Seppänen @ 2005-02-21 21:49 UTC (permalink / raw)
  To: zsh-users

21.2.2005 kello 16:51, Mika Seppänen wrote:

> I found that by reading manuals and using google, but It doesn't help.
>
> I get following: (PS1=%s\> and option autonamedirs unset, though 
> seting it doesn't change situation in anyway)

Solved. I had following defination in my .zshrc:

export foo="/home/bar/project/random/"

Problem was slash at end of directory, following works great:

export foo="/home/bar/project/random"

Both work with cd, but only later expand correctly from %~. 
Unfortunatly instead of realizing that right away I walk through the 
hard way. First I made some tests on other platforms (with different 
config files) and it worked there, so I thought that maybe platform is 
reason to faulty behaviour. Because of my blindness to see obivious I 
had to run zsh under gdb on two different platforms to see that little 
difference :)

Mika


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

* Re: Named directories
  2005-02-21 14:51   ` Mika Seppänen
  2005-02-21 21:49     ` Mika Seppänen
@ 2005-02-22  4:35     ` Seth Kurtzberg
  2005-02-22 11:54       ` Mika Seppänen
  1 sibling, 1 reply; 11+ messages in thread
From: Seth Kurtzberg @ 2005-02-22  4:35 UTC (permalink / raw)
  To: Mika Seppänen; +Cc: zsh-users

Mika Seppänen wrote:

> 21.2.2005 kello 16:31, Peter Stephenson wrote:
>
>> You need to refer to "~work" at least once; the usual trick is to put
>>
>> : ~work
>>
>> in your .zshrc after defining the directory.  You can also "setopt
>> autonamedirs" to make all such parameters eligible for this
>> replacement.
>
His situation is that the directory he is talking about has two names, 
and if he refers to it as, say, ~a, the prompt shows ~b.  I've seen the 
same thing, although I've never considered it difficult to work with, as 
long as (in his case) ~work gets you where you want to go.

For example, I have the following (and sorry if I'm misinterpreting the 
question):

export UTILDIR=/a/b/c
export ud=$UTILDIR

then ~UTILDIR takes me to the correct place (since I have the setopt's 
required to do this), but the prompt shows  ~ud, not ~UTILDIR.

It would, from my perspective, be nice to say   ~ud    and have it 
displayed in the prompt as  ~UTILDIR (less typing, more meaningful prompt).

If this is not an anaologous situation, would someone please tell me 
why, and how it relates to the original question?

TIA

>
> I found that by reading manuals and using google, but It doesn't help.
>
> I get following: (PS1=%s\> and option autonamedirs unset, though 
> seting it doesn't change situation in anyway)
>
> ~>cd work
> ~/Projektit/rnd/ott/sip.imp
> ~/Projektit/rnd/ott/sip.imp>pwd
> /Users/c8z/Projektit/rnd/ott/sip.imp
> ~/Projektit/rnd/ott/sip.imp>cd foo
> ~foo
> ~foo>pwd
> /usr/local/etc
> ~foo>
>
> (zsh 4.1.1 on Mac OS X)
>
> Mika
>
>
> !DSPAM:4219f941108266494394366!
>



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

* Re: Named directories
  2005-02-22  4:35     ` Seth Kurtzberg
@ 2005-02-22 11:54       ` Mika Seppänen
  2005-02-22 13:09         ` Seth Kurtzberg
  0 siblings, 1 reply; 11+ messages in thread
From: Mika Seppänen @ 2005-02-22 11:54 UTC (permalink / raw)
  To: Seth Kurtzberg; +Cc: zsh-users

> 21.2.2005 kello 16:31, Peter Stephenson wrote:
>
> For example, I have the following (and sorry if I'm misinterpreting 
> the question):

I already solved it. Problem was slash at end of path. This is is 
possibly a bug in zsh, but in any case it can be used as hack to get 
behaviour you stated bellow:

> export UTILDIR=/a/b/c
> export ud=$UTILDIR

If I write that in a little bit different way:

export UTILDIR="/a/b/c"
export ud="$UTILDIR/"

Now you can use both with cd-command, but %~ expands to UTILDIR not ud, 
because of slash at end of ud.

Mika


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

* Re: Named directories
  2005-02-22 11:54       ` Mika Seppänen
@ 2005-02-22 13:09         ` Seth Kurtzberg
  0 siblings, 0 replies; 11+ messages in thread
From: Seth Kurtzberg @ 2005-02-22 13:09 UTC (permalink / raw)
  To: Mika Seppänen; +Cc: zsh-users

Mika Seppänen wrote:

>> 21.2.2005 kello 16:31, Peter Stephenson wrote:
>>
>> For example, I have the following (and sorry if I'm misinterpreting 
>> the question):
>
>
> I already solved it. Problem was slash at end of path. This is is 
> possibly a bug in zsh, but in any case it can be used as hack to get 
> behaviour you stated bellow:
>
>> export UTILDIR=/a/b/c
>> export ud=$UTILDIR
>
>
> If I write that in a little bit different way:
>
> export UTILDIR="/a/b/c"
> export ud="$UTILDIR/"
>
> Now you can use both with cd-command, but %~ expands to UTILDIR not 
> ud, because of slash at end of ud.

That makes the prompt _always_ UTILDIR.  That isn't what I want.  I want 
~ud to display ~ud, and ~UTILDIR display ~UTILDIR.  You gave me a way to 
choose one, but that's the original problem (that I can only displya one)

>
> Mika
>
>
> !DSPAM:421b2110173271353218223!
>



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

* Re: Named directories
  2005-02-21 14:17 Named directories Mika Seppänen
  2005-02-21 14:21 ` Vincent Lefevre
  2005-02-21 14:31 ` Peter Stephenson
@ 2005-02-26 22:17 ` Bart Schaefer
  2 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2005-02-26 22:17 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1014 bytes --]

On Mon, 21 Feb 2005, Mika Seppänen wrote:

> If my homedir is /home/foo and I have named directory:
> 
> work=/home/foo/bar
> 
> Then if I switch to that dir (cd work), %~ expands to ~/bar. Is there any way
> to make it expand to ~work?

One thing that no one has mentioned in this thread is that %~ will always 
expand to the shortest possible string.

Thus, given

two=$HOME/bin
three=$HOME/bin
four=$HOME/bin

you'll always see ~two because "two" is shorter than "/bin".  Even if you 
"unset two", you'll never see ~three because both "/bin" and "four" are 
shorter than "three".  Because ~/bin and ~four are of equal length, what 
you see is (I believe) dependent on hash table ordering, and therefore 
unpredictable (though it should always be consistent).

Hey, PWS and the UTF-8 gang:  If "bin" were in fact a name consisting of
three wide characters, i.e., they display as three characters but occupy
6 or more bytes, would the prompt code treat ~three as a shorter string
for purposes of the %~ expansion?

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

* Re: named directories
  2005-08-07  3:47 named directories UVV
@ 2005-08-07 10:00 ` J
  0 siblings, 0 replies; 11+ messages in thread
From: J @ 2005-08-07 10:00 UTC (permalink / raw)
  To: UVV; +Cc: zsh-users

> What difference between named directory and home directory?

The named directories are a list of directories for which a name is associated
explicitly by the user. That way, you can use the alias instead of the full
directory name. For example, if there is a variable
mydir=/home/me/foo/bar/qux
you can use ~mydir instead of /home/me/foo/bar/qux

The named directories are defined by the user by setting a variable to a valid
path ; there can be as many as you want.


The home directories are the directories where users have their actual home.
This is defined by how the system is installed and can usually be changed
by root only. The shell treats the name of the user exactly as if it was a
named directory pointing to the home of the user, though there is no variable
by that name. The home directories are defined in /etc/passwd, and are not
only used by the shell but a variety of other things, including the system
itself, even if most of the time the shell is the one who does the actual
substitution.


A last difference is that home directories can be reffered to as ~user in every
shell I can think of, whereas named directories work in zsh only (and maybe
ksh, I can't remember).

-- 
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."


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

* named directories
@ 2005-08-07  3:47 UVV
  2005-08-07 10:00 ` J
  0 siblings, 1 reply; 11+ messages in thread
From: UVV @ 2005-08-07  3:47 UTC (permalink / raw)
  To: zsh-users

What difference between named directory and home directory?


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

end of thread, other threads:[~2005-08-07 10:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-21 14:17 Named directories Mika Seppänen
2005-02-21 14:21 ` Vincent Lefevre
2005-02-21 14:31 ` Peter Stephenson
2005-02-21 14:51   ` Mika Seppänen
2005-02-21 21:49     ` Mika Seppänen
2005-02-22  4:35     ` Seth Kurtzberg
2005-02-22 11:54       ` Mika Seppänen
2005-02-22 13:09         ` Seth Kurtzberg
2005-02-26 22:17 ` Bart Schaefer
2005-08-07  3:47 named directories UVV
2005-08-07 10:00 ` J

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