Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
10
Help us understand the problem. What is going on with this article?
@otchy

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

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

10
Help us understand the problem. What is going on with this article?
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
otchy
1979 年 2 月 10 日生まれ / 仕事: Web システム開発 / 好きなもの: IT 全般、科学分野 / 座右の銘: 明日は明日の風が吹く / 好きな言葉: ハードルは高ければ高いほどくぐりやすい

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
10
Help us understand the problem. What is going on with this article?