zsh-users
 help / color / mirror / code / Atom feed
* cd x x.something
@ 2017-09-25  2:19 tuxic
  2017-09-25  3:55 ` Amir Ish-Hurwitz
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: tuxic @ 2017-09-25  2:19 UTC (permalink / raw)
  To: zsh-users

Hi,

zsh has a feature, which I love and use a lot:

cd A B

If you are in a directory

/abcd/efgh/ijk

and want to go to

/abcdefgh/lmn

simply type

cd ijk lmn

. But suppose there are these two directories

/a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice
/a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice.bak

and you are in the first one and you want to go to the seond one....
do you really need to type in "ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice"
twice when you want to use this

cd A B

feature (I know of othere ways to easily to this ../<TAB> for
example...but for this I /insist/ :) of using this cd A B feature :) 
?

Cheers
Meino


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

* Re: cd x x.something
  2017-09-25  2:19 cd x x.something tuxic
@ 2017-09-25  3:55 ` Amir Ish-Hurwitz
  2017-09-25  7:25 ` Dominik Vogt
  2017-09-26 18:50 ` Roman Neuhauser
  2 siblings, 0 replies; 9+ messages in thread
From: Amir Ish-Hurwitz @ 2017-09-25  3:55 UTC (permalink / raw)
  To: zsh-users

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

>
> /abcd/efgh/ijk
>
> /abcdefgh/lmn
>
> cd ijk lmn
>

​I suppose you meant ​/abcd*/*efgh/lmn 😏

What cd A B really does is simply replace the first occurance of string A
in $PWD with string B and cd to the result.

/a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice

/a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTy
> peInTwice.bak
>

​I'd simply type *cd $PWD $PWD.bak* in this particular case​ as that's the
shortest option I can think of.

Regards,
Amir

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

* Re: cd x x.something
  2017-09-25  2:19 cd x x.something tuxic
  2017-09-25  3:55 ` Amir Ish-Hurwitz
@ 2017-09-25  7:25 ` Dominik Vogt
  2017-09-26 18:50 ` Roman Neuhauser
  2 siblings, 0 replies; 9+ messages in thread
From: Dominik Vogt @ 2017-09-25  7:25 UTC (permalink / raw)
  To: zsh-users

On Mon, Sep 25, 2017 at 04:19:28AM +0200, tuxic@posteo.de wrote:
> . But suppose there are these two directories
> 
> /a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice
> /a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice.bak
> 
> and you are in the first one and you want to go to the seond one....
> do you really need to type in "ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice"
> twice when you want to use this
> 
> cd A B

You don't have to type the whole pth component, just the part you
want to replace:

 $ cd e e.bak

(unfortunately the first argument cannot be empty; "cd '' .bak"
does not work (why?)).

Or to get back, even

 $ cd .bak ""

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt


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

* Re: cd x x.something
  2017-09-25  2:19 cd x x.something tuxic
  2017-09-25  3:55 ` Amir Ish-Hurwitz
  2017-09-25  7:25 ` Dominik Vogt
@ 2017-09-26 18:50 ` Roman Neuhauser
  2017-09-26 19:47   ` Grant Taylor
  2 siblings, 1 reply; 9+ messages in thread
From: Roman Neuhauser @ 2017-09-26 18:50 UTC (permalink / raw)
  To: zsh-users

# tuxic@posteo.de / 2017-09-25 04:19:28 +0200:
> Hi,
> 
> zsh has a feature, which I love and use a lot:
> 
> cd A B

> . But suppose there are these two directories
> 
> /a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice
> /a/b/ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice.bak
> 
> and you are in the first one and you want to go to the seond one....
> do you really need to type in "ThisIsARedicoluousLongDirectoryNameWhichNoPersonWillReallyTypeInTwice"
> twice when you want to use this

cd $PWD.bak

-- 
roman


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

* Re: cd x x.something
  2017-09-26 18:50 ` Roman Neuhauser
@ 2017-09-26 19:47   ` Grant Taylor
  2017-09-26 23:56     ` Roman Neuhauser
  0 siblings, 1 reply; 9+ messages in thread
From: Grant Taylor @ 2017-09-26 19:47 UTC (permalink / raw)
  To: zsh-users

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

On 09/26/2017 12:50 PM, Roman Neuhauser wrote:
> cd $PWD.bak

That doesn't work for me.  -  It's also one directory, not the two that 
I think is needed to move laterally.

Did you by chance mean the following:

cd $PWD{,.bak}

Which expands to two directories, the first with no suffix and the 
second with the .bak suffix?



-- 
Grant. . . .
unix || die


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3717 bytes --]

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

* Re: cd x x.something
  2017-09-26 19:47   ` Grant Taylor
@ 2017-09-26 23:56     ` Roman Neuhauser
  2017-09-27  1:23       ` Grant Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Roman Neuhauser @ 2017-09-26 23:56 UTC (permalink / raw)
  To: Grant Taylor; +Cc: zsh-users

# gtaylor@tnetconsulting.net / 2017-09-26 13:47:23 -0600:
> On 09/26/2017 12:50 PM, Roman Neuhauser wrote:
> > cd $PWD.bak
> 
> That doesn't work for me.

can you elaborate how?  it surely should:

$ mkdir omg omg.wtf
$ cd omg
$ pwd
/home/roman/omg
$ cd $PWD.wtf
$ pwd
/home/roman/omg.wtf

> -  It's also one directory, not the two that I
> think is needed to move laterally.

`cd foo bar` does not "move laterally", it's like `cd ${PWD:s#foo#bar}`,
except `foo` is not treated as a glob.  this doesn't look lateral to me:

$ mkdir x
$ cd x
$ pwd
/home/roman/x
$ mkdir -p .$PWD
$ cd / ./
$ pwd
/home/roman/x/home/roman/x

> Did you by chance mean the following:
> 
> cd $PWD{,.bak}
> 
> Which expands to two directories, the first with no suffix and the second
> with the .bak suffix?

no, i meant what i wrote: since the second directory differs from $PWD
only in the ".bak" suffix, `cd $PWD.bak` will have the desired effect.

-- 
roman


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

* Re: cd x x.something
  2017-09-26 23:56     ` Roman Neuhauser
@ 2017-09-27  1:23       ` Grant Taylor
  2017-09-27  3:47         ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Grant Taylor @ 2017-09-27  1:23 UTC (permalink / raw)
  To: Roman Neuhauser; +Cc: zsh-users

On 09/26/2017 05:56 PM, Roman Neuhauser wrote:
> can you elaborate how?  it surely should:

I'll have to look at my command history at work where I tried this.

> $ mkdir omg omg.wtf
> $ cd omg
> $ pwd
> /home/roman/omg
> $ cd $PWD.wtf
> $ pwd
> /home/roman/omg.wtf

That works for me at home.

I'm guessing that I used "omg.wtf" instead of "$PWD.wtf".  Which leads 
me to think that this is something special that acts on the PWD 
environment variable.

Or there's some sort of environment variable permutation that I'm not 
aware of.  Which is completely possible.

> `cd foo bar` does not "move laterally", it's like `cd ${PWD:s#foo#bar}`,
> except `foo` is not treated as a glob.  this doesn't look lateral to me:
> 
> $ mkdir x
> $ cd x
> $ pwd
> /home/roman/x
> $ mkdir -p .$PWD
> $ cd / ./
> $ pwd
> /home/roman/x/home/roman/x

Okay, I see what you're saying.

% cd /dev/shm
% mkdir omg omg.wtf
% cd omg
% pwd
/dev/shm/omg
% cd omg omg.wtf
% pwd
/dev/shm/omg.wtf

That's why I was saying laterally.

> no, i meant what i wrote: since the second directory differs from $PWD
> only in the ".bak" suffix, `cd $PWD.bak` will have the desired effect.

Fair.

Thank you for the explanation Roman.



-- 
Grant. . . .
unix || die


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

* Re: cd x x.something
  2017-09-27  1:23       ` Grant Taylor
@ 2017-09-27  3:47         ` Bart Schaefer
  2017-09-27  4:05           ` Grant Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2017-09-27  3:47 UTC (permalink / raw)
  To: zsh-users

On Sep 26,  7:23pm, Grant Taylor wrote:
}
} I'm guessing that I used "omg.wtf" instead of "$PWD.wtf".  Which leads 
} me to think that this is something special that acts on the PWD 
} environment variable.

No, there's nothing special here.  The value of $PWD is a full path, to
which you are appending ".wtf".

} % pwd
} /dev/shm/omg
} % cd omg omg.wtf
} % pwd
} /dev/shm/omg.wtf
} 
} That's why I was saying laterally.

Yes, but you could also do "cd dev/shm tmp" and it would try to change
to /tmp/omg.  It's only "lateral" because you happen to be using a
string that matches only the tail of the path.


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

* Re: cd x x.something
  2017-09-27  3:47         ` Bart Schaefer
@ 2017-09-27  4:05           ` Grant Taylor
  0 siblings, 0 replies; 9+ messages in thread
From: Grant Taylor @ 2017-09-27  4:05 UTC (permalink / raw)
  To: zsh-users

On 09/26/2017 09:47 PM, Bart Schaefer wrote:
> No, there's nothing special here.  The value of $PWD is a full path, to
> which you are appending ".wtf".

*facePalm*

I completely missed that simple low hanging fruit.

I'm done for the day.

/me turns and hollers "Check please."

> Yes, but you could also do "cd dev/shm tmp" and it would try to change
> to /tmp/omg.  It's only "lateral" because you happen to be using a
> string that matches only the tail of the path.

Thank you for trying to explain this.  My brain is not accepting it.

I'll get some sleep and (re)read some manuals to try to pick up what I'm 
missing or have forgotten.



-- 
Grant. . . .
unix || die


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

end of thread, other threads:[~2017-09-27  4:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-25  2:19 cd x x.something tuxic
2017-09-25  3:55 ` Amir Ish-Hurwitz
2017-09-25  7:25 ` Dominik Vogt
2017-09-26 18:50 ` Roman Neuhauser
2017-09-26 19:47   ` Grant Taylor
2017-09-26 23:56     ` Roman Neuhauser
2017-09-27  1:23       ` Grant Taylor
2017-09-27  3:47         ` Bart Schaefer
2017-09-27  4:05           ` Grant Taylor

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