Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

よく使うディレクトリをブックマークする 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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした