zsh chdir 可以搜索并匹配历史记录吗?

Dan*_*Lin 5 zsh

我是 zsh 的新手。

如果它是唯一的,我可以输入类似cd %wiki跳转到的内容吗?~/prj/golang/gowiki

但如果有两个以上的目录可供使用cd %unix,则仅显示匹配的目录。

这是我的样本目录历史记录。

$ dirs -v  
0   ~/prj/golang
1   ~
2   ~/prj/unixconf
3   ~/prj/unixconf/srv
4   ~/memo
5   ~/prj/golang/gowiki
Run Code Online (Sandbox Code Playgroud)

Jos*_*Gee 3

请参阅 zshall 元手册页 ( man zshall) 以最简单的方式了解许多精彩的 zsh 技巧。另外值得注意的是 zshcontrib 和 zshmisc 联机帮助页。

\n\n

以下摘录可帮助您更轻松地记住目录堆栈中的目录。

\n\n
REMEMBERING RECENT DIRECTORIES\n   The function cdr allows you to change the working directory to a previous\n   working directory from a list maintained automatically.  It is similar in\n   concept to the directory stack controlled by the pushd, popd and dirs\n   builtins,  but  is  more  config\xe2\x80\x90 urable,  and  as it stores all entries\n   in files it is maintained across sessions and (by default) between\n   terminal emulators in the current session.  (The pushd directory stack is\n   not actually modified or used by cdr unless you configure it to do so as\n   described in the configuration section below.)\n\nInstallation\n   The system works by means of a hook function that is called every time\n   the directory changes.  To install the system, autoload the required\n   functions and use the add-zsh-hook function described above:\n\n          autoload -Uz chpwd_recent_dirs cdr add-zsh-hook\n          add-zsh-hook chpwd chpwd_recent_dirs\n\n   Now every time you change directly interactively, no matter which command\n   you use, the directory to which you change will be remembered in\n   most-recent-first order.\n\nUse\nAll direct user interaction is via the cdr function.\n\n   The argument to cdr is a number N corresponding to the Nth most recently\n   changed-to directory.  1 is the immediately preceding directory; the\n   current directory is remembered but is not offered as a destination.\n   Note that if you have  multiple  windows open 1 may refer to a directory\n   changed to in another window; you can avoid this by having per-terminal\n   files for storing directory as described for the recent-dirs-file style\n   below.\n\n   If you set the recent-dirs-default style described below cdr will behave\n   the same as cd if given a non-numeric argument, or more than one\n   argument.  The recent directory list is updated just the same however you\n   change directory.\n\n   If the argument is omitted, 1 is assumed.  This is similar to pushd's\n   behaviour of swapping the two most recent directories on the stack.\n\n   Completion for the argument to cdr is available if compinit has been run;\n   menu selection is recommended, using:\n\n          zstyle ':completion:*:*:cdr:*:*' menu selection\n\n   to  allow  you to cycle through recent directories; the order is\n   preserved, so the first choice is the most recent directory before the\n   current one.  The verbose style is also recommended to ensure the\n   directory is shown; this style is on by default so no action is required\n   unless you have changed it.\n
Run Code Online (Sandbox Code Playgroud)\n\n

对于命名目录,您需要使用hash -d name=/path并将其放入 zshrc 中。然后你可以 cd 到这些目录cd ~name

\n