2012-03-05 125 views
2

我是zsh的新手。zsh chdir可以搜索並匹配歷史記錄嗎?

如果它是唯一的,我可以輸入類似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 

回答

1

指的是最簡單的訪問zshall元手冊,瞭解許多美妙的zsh技巧。也值得注意的是zshcontrib和zshmisc手冊。

這裏是一個摘錄,以幫助記住目錄在dirstack更容易。

REMEMBERING RECENT DIRECTORIES 
    The function cdr allows you to change the working directory to a previous working directory from a list maintained automatically. It is similar in concept to the directory stack controlled by the pushd, popd and dirs builtins, but is more config‐ 
    urable, and as it stores all entries in files it is maintained across sessions and (by default) between terminal emulators in the current session. (The pushd directory stack is not actually modified or used by cdr unless you configure it to do so as 
    described in the configuration section below.) 

Installation 
    The system works by means of a hook function that is called every time the directory changes. To install the system, autoload the required functions and use the add-zsh-hook function described above: 

      autoload -Uz chpwd_recent_dirs cdr add-zsh-hook 
      add-zsh-hook chpwd chpwd_recent_dirs 

    Now every time you change directly interactively, no matter which command you use, the directory to which you change will be remembered in most-recent-first order. 

Use 
All direct user interaction is via the cdr function. 

    The argument to cdr is a number N corresponding to the Nth most recently changed-to directory. 1 is the immediately preceding directory; the current directory is remembered but is not offered as a destination. Note that if you have multiple windows 
    open 1 may refer to a directory changed to in another window; you can avoid this by having per-terminal files for storing directory as described for the recent-dirs-file style below. 

    If you set the recent-dirs-default style described below cdr will behave the same as cd if given a non-numeric argument, or more than one argument. The recent directory list is updated just the same however you change directory. 

    If the argument is omitted, 1 is assumed. This is similar to pushd's behaviour of swapping the two most recent directories on the stack. 

    Completion for the argument to cdr is available if compinit has been run; menu selection is recommended, using: 

      zstyle ':completion:*:*:cdr:*:*' menu selection 

    to allow you to cycle through recent directories; the order is preserved, so the first choice is the most recent directory before the current one. The verbose style is also recommended to ensure the directory is shown; this style is on by default so 
    no action is required unless you have changed it. 

爲命名的目錄,你會希望使用hash -d name=/path並在zshrc扔了吧。然後你可以cd到那些與dirs cd ~name

玩得開心。

+0

我不知道這個名字的目錄哈希值。很酷! – jackrabbit 2013-12-02 08:19:50

1

我不認爲你可以得到,如果沒有刻錄CD的自定義版本(即創建一個名爲cd功能將從builtin cd接管

你可以這樣做:

DIRSTACKSIZE=20 
setopt auto_pushd # Make cd push the old directory onto the directory stack. 
setopt pushd_ignore_dups # Ignore duplicates at the directory stack. 
setopt pushd_minus # makes the whole pushd list easier to use from 'cd' 

然後,如果你做了

% cd -[TAB] 
1 -- /tmp 
2 -- /etc 

你可以只使用數量:

cd -2 # jumps to /etc 

另請注意,您可以使用其他命令(MV,CP等)目錄棧通過~-NUMBER

mv notes.txt ~-[TAB] 
1 -- /tmp 
2 -- /etc 
3 -- /my/very/complicated/dir/path