Qiita Conference 2025

Qiita史上最多!豪華12名のゲストが登壇

特別講演ゲスト(敬称略)

ymrl、成瀬允宣、鹿野壮、伊藤淳一、uhyo、徳丸浩、ミノ駆動、みのるん、桜庭洋之、tenntenn、けんちょん、こにふぁー

9
9

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.

bash でもよく使うディレクトリをブックマークしたい

Last updated at Posted at 2014-03-22

よく使うディレクトリをブックマークする zsh のプラグイン なんていう記事を見たので、bash で似たような事をやってる方法を共有します。

.bashrc にこんなの書くと、ショートカットが定義できます。タブ補完も OK。
bash 初心者なので、突っ込み歓迎です。

declare -A shortDirs
shortDirs=(\
  ["log"]="/var/log"\
  ["loghttpd"]="/var/log/httpd"\
)
goto(){
  for key in ${!shortDirs[*]}; do
    if [ "$key" = "$1" ]; then
      cd ${shortDirs[$key]}
      return 0
    fi
  done
  cd ~
}
gotoParams=""
for key in ${!shortDirs[*]}; do
  gotoParams="$gotoParams $key"
done
complete -W "$gotoParams" goto

この例だと

$ goto l<tab>
で
$ goto log ---> cd /var/log

$ goto l<tab>h<tab>
で
$ goto loghttpd ---> cd /var/log/httpd

になるので、ショートカットの定義次第でいい感じになります。

9
9
4

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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?