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?
相关问题
- How to get the return code of a shell script in lu
- Google places autocomplete suggestion without coun
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- “command not found” errors in expect script execut
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Set the z-index value of a jQuery autocomplete inp
- Launch interactive SSH bash session from PHP
- Generate disk usage graphs/charts with CLI only to
- How can I create a small IDLE-like Python Shell in
If you use
pushd
instead ofcd
, then you can list directories withdirs
and cd to old directory withpopd
. You can also setautopush
option to getcd
behave much likepushd -q
. Here is an example:Note that
pushd
does not remove anything from the directory stack, it only rotates it. Seeman zshbuiltins
for more details.If you have
setopt AUTO_PUSHD
in your.zshrc
thencd
will automatically do apushd
of each directory you change to. Taking the example from ZyX:You can see a list of the directories using
dirs
:To be able to tab complete the list you can use the
+
and-
arguments withcd
(<TAB>
meaning you hit the tab key):Or the reverse:
Then just select the number to go to that directory:
Tab Complete Directories
I always forget the magic sequence to do the following so I updated the answer to explain this part.
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 (~
).Make some directories in
3
to make this example better.Then find the directory in the stack.
Then use tab completion on an entry.
c- minus is designed for this kind of requirement.
It support regex match, using md5 hash to void duplication in
pushd
.Easily to dump and load.
This gif shows some basic operations.
you can check it out on https://github.com/whitebob/cminus