You are not logged in.

#1 2010-11-23 08:35:40

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

[SOLVED] [zsh] Change default cd behavior

Hey guys!

In my .bash_aliases file I had something like this:

cd_func() 
{
    cd $1 && ls
}
alias cd='cd_func'

It showed me the directories from the directory that I moved into. When adding this to a .zshrc (or .zsh_aliases) it complains about ...

maximum nested function level reached

... because it creates an infinite loop. How can I achieve my desired behaviour? I am using grml-zsh-config and saw there's a "cl" function which does exactly the same as I want (cd && ls) but I still have to type cl instead of cd everytime I want to change directory.
So I tried ...

alias cd='cl'

... but there's the infinite loop again. sad

Please, someone help me.

Last edited by akurei (2010-11-23 21:28:07)

Offline

#2 2010-11-23 11:44:42

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: [SOLVED] [zsh] Change default cd behavior

Either use the `builtin` keyword inside your function to prevent the function from being recursively called, or (even better) use the zsh provided chpwd() hook to run ls instead.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#3 2010-11-23 17:56:20

thestinger
Package Maintainer (PM)
From: Toronto, Canada
Registered: 2010-01-23
Posts: 478

Re: [SOLVED] [zsh] Change default cd behavior

or just name your function "cd" and avoid the alias

Offline

#4 2010-11-23 21:26:04

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

Re: [SOLVED] [zsh] Change default cd behavior

rson451 wrote:

Either use the `builtin` keyword

Yes! That did the trick!

in ~/.zsh_aliases:

cd()
{
    builtin cd $1 && ls
}

inside your function to prevent the function from being recursively called, or (even better) use the zsh provided chpwd() hook to run ls instead.

chpwd() hook? Could you please give an example for me?

thestinger wrote:

or just name your function "cd" and avoid the alias

That did not work, unfortunately.

Thanks, both of you!

Last edited by akurei (2010-11-23 21:26:41)

Offline

#5 2010-11-23 22:34:10

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: [SOLVED] [zsh] Change default cd behavior

akurei wrote:

chpwd() hook? Could you please give an example for me?

See my zshrc in my dotfiles repo below.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

Board footer

Powered by FluxBB