84
77

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

1分で実現できる有用な技術Advent Calendar 2013

Day 20

ディレクトリ移動を手軽にするauto cdとcdpath

Posted at

AUTO_CD

setopt AUTO_CDの1行を~/.zshrcに設定しておくと,ディレクトリ移動時にcdを打たなくても,ディレクトリと解釈できる文字列を打てばcdしてくれる

~/.zshrc
setopt AUTO_CD
cd foo/bar/baz # 設定前
foo/bar/baz    # 設定後

これによりcdはホームディレクトリに移動するとき以外は使う必要がなくなる.ディレクトリ名がコマンド名と被ってしまうようなときは./rubyのように指定すればよい.cd rubyよりは楽.

cdpath

そしてAUTO_CDcdpathを合わせて設定するとより強力

~/.zshrc
setopt AUTO_CD
cdpath=(.. ~ ~/src)

この2行を追加しておけば,親ディレクトリやホームディレクトリ,~/src以下へはどこからでもディレクトリ名だけで移動できるようになる.プロジェクト間の移動も一瞬.

マニュアル

一応マニュアルへの参照を.それぞれman zshoptions, man zshparamに載っている.

$ man zshoptions
...
 AUTO_CD (-J)
              If a command is issued that can't be executed as a normal command, and the command is the name of a directory, perform the cd command to that directory.
...
$ man zshparam
...
cdpath <S> <Z> (CDPATH <S>)
              An array (colon-separated list) of directories specifying the search path for the cd command.
...
84
77
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
84
77

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?