CD -1,-2,-3等等Z中壳 [英] cd -1, -2, -3 etc in Z shell

查看:124
本文介绍了CD -1,-2,-3等等Z中壳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何设置Z轴的外壳,使得键入cd - ?给你$ P $列表pviously访问路径,以及CD -1,-2,-3等,然后将带您到的目录

How do you set up the Z shell such that typing cd - gives you a list of previously visited paths, and cd -1, -2, -3, etc. will then take you to the directories?

推荐答案

如果您有 SETOPT AUTO_PUSHD .zshrc 然后 CD 将自动做一个 PUSHD 每次更改到目录。以从ZYX的例子:

If you have setopt AUTO_PUSHD in your .zshrc then cd will automatically do a pushd of each directory you change to. Taking the example from ZyX:

$ setopt AUTO_PUSHD
$ mkdir -p 1/2/3/4
$ cd 1
$ cd 2
$ cd 3
$ cd 4

您可以看到使用迪尔斯目录的列表:

You can see a list of the directories using dirs:

$ dirs -v
0    ~/1/2/3/4
1    ~/1/2/3
2    ~/1/2
3    ~/1
4    ~

要能够使用Tab键完成,您可以使用列表中的 + - 与<$ C $参数C> CD (&LT;标签&gt; 意思是你按下TAB键):

To be able to tab complete the list you can use the + and - arguments with cd (<TAB> meaning you hit the tab key):

$ cd +<TAB>
1 -- ~/1/2/3
2 -- ~/1/2
3 -- ~/1
4 -- ~

或者相反的:

$ cd -<TAB>
0 -- ~
1 -- ~/1
2 -- ~/1/2
3 -- ~/1/2/3

然后,只需选择数字要到该目录:

Then just select the number to go to that directory:

$ cd +2
$ pwd
~/1/2

标签的完整目录

我总是忘了神奇的顺序做以下,所以我更新了答案来解释这一部分。

Tab Complete Directories

I always forget the magic sequence to do the following so I updated the answer to explain this part.

+ - 将只需要你的目录,你不能完成选项卡中的路径堆栈(即 CD -2 /&LT;标签&gt; 为您提供了什么)。为了使这项工作,你可以使用一个波浪号()。

The + and - will only take you to the directory, you can't tab complete the path in the stack (i.e. cd -2/<TAB> gives you nothing). To make this work, you can use a tilde (~).

请在 3 一些目录,以使这个例子更好。

Make some directories in 3 to make this example better.

$ mkdir 3/foo 3/bar 3/baz

然后找出堆栈中的目录。

Then find the directory in the stack.

$ cd ~+<TAB>
1 -- ~/1/2/3/4
2 -- ~/1/2/3
3 -- ~/1
4 -- ~

然后在一个条目使用制表符完成。

Then use tab completion on an entry.

$ cd ~+2/<TAB>
4/    bar/  baz/  foo/

这篇关于CD -1,-2,-3等等Z中壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆