2012-03-05 2 views
2

저는 zsh의 초보자입니다.zsh chdir 검색 및 일치 기록을 검색 할 수 있습니까?

cd %wiki과 같이 입력하면 ~/prj/golang/gowiki으로 바뀔 수 있습니다.

그러나 cd %unix에 대해 2 개 이상의 디렉토리가있는 경우 일치하는 디렉토리 만 표시하십시오.

여기 내 샘플 디렉터리 기록입니다.

$ dirs -v 
0 ~/prj/golang 
1 ~ 
2 ~/prj/unixconf 
3 ~/prj/unixconf/srv 
4 ~/memo 
5 ~/prj/golang/gowiki 

답변

1

많은 멋진 zsh 트릭에 대해 알아 보려면 가장 쉬운 액세스를 위해 zshall 메타 맨 페이지를 참조하십시오. 또한 주목할만한 것은 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를 보낼 수 있습니다. cd ~name

재미 있습니다.

난 당신이 IE가 builtin cd부터 걸릴 것 cd라는 함수를 만드는 (CD의 사용자 지정 버전을 작성하지 않고

당신은 같은 것을 할 수 있다는 것을 얻을 수 있다고 생각하지 않습니다

+0

을 통해 다른 명령 (MV, CP 등)에서 디렉토리 스택을 사용할 수있는 것을 알 수 있습니다. 아주 멋지다! – jackrabbit

1

:.

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 

또한 당신은 내가 이름 디렉토리 해시에 대해 알고하지 않았다 ~-NUMBER

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