无法理解Zsh的autopushd的好处

我有.zshrc

setopt autopushd 

这使得CD行为像pushd。 这意味着我们没有堆栈。 当我使用它时,我根本没有使用堆栈,因为它从我身上移除了堆栈。

我不确定autopushd有什么好处。

autopushd有什么好处?

pushd就像cd一样,但是它也将当前目录压入堆栈。 你可能在/ some / deep /目录下,然后需要在/ var / www中查找一段时间:

 crb@server /some/deep/directory $ pushd /var/www/ /var/www /some/deep/directory crb@server /var/www $ [do some stuff] crb@server /var/www $ popd /some/deep/directory crb@server /some/deep/directory $ 

autopushd意味着即使你input'cd',你也会得到键入'pushd'的效果,你不记得你想用的东西,直到你认为“男人,我真的希望我能回到我之前的地方”。 然后,你可以通过你的目录历史logging回来。

通过键入'cd – ',知道你可以随时切换到你所在的目录(而不是父目录)。

这是另一个好的写法 。

编辑为什么使用pushd,当你可以使用cd – ?

 cd /foo/bar cd /baz cd /somewhere/else 

CD – 只会让你到/巴兹。 在你input“cd / foo / bar”之前,pushd会让你一路回到原来的位置。

目录栈在脚本中特别有用,在这个脚本中你不能回顾你的命令历史并且能够识别你所在目录的名字:

 pushd /var/foo # run a command, which might well change your PWD at the end of its execution - especially if it fails popd 

您现在保证在/ var / foo中。