Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Navigate up 'n' directories #70

Open
alxtlm opened this issue Sep 8, 2022 · 4 comments
Open

Feature request: Navigate up 'n' directories #70

alxtlm opened this issue Sep 8, 2022 · 4 comments

Comments

@alxtlm
Copy link

alxtlm commented Sep 8, 2022

I often find myself doing commands like this
cd ../../../../../

Is there a shortcut I can use that will cd ../ n times?
z 5

@simone-viozzi
Copy link

On zsh you can do

cd ....

And it will jump back 3 directories.

@agkozak
Copy link
Owner

agkozak commented Oct 9, 2022

On zsh you can do
cd ....

Are you using a global alias to do that, like

alias -g ....='../../..'

?

@alxtlm, I recommend you try the ZSH-LOVERS rationalise-dot method:

rationalise-dot() {
    if [[ $LBUFFER = *.. ]]; then
        LBUFFER+=/..
    else
        LBUFFER+=.
    fi
}
zle -N rationalise-dot
bindkey . rationalise-dot

If you put that in your .zshrc, then typing ... expands ../.. on the command line; .... expands to ../../..; and so on. Give it a try. If you also use

setopt AUTO_CD

you can just start typing . repeatedly at the prompt and you won't need to type cd.

I think that's better than introducing a new behavior for Zsh-z; good to keep these things simple and predictable, right?

@simone-viozzi
Copy link

On zsh you can do
cd ....

Are you using a global alias to do that, like

alias -g ....='../../..'

?

Yes, but I never defined them, and I thought they were defined by zsh itself. Maybe they are added by some plugin, sorry.

@agkozak
Copy link
Owner

agkozak commented Oct 9, 2022

Yes, but I never defined them, and I thought they were defined by zsh itself. Maybe they are added by some plugin, sorry.

No problem! It's good for people to see that you can do that, too. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants