Bash itを使ってbashの設定をいい感じにする
すっかり暑くなってきて汗かきな自分につらい季節になってきました。森です。
環境設定するのは大変だ
最近、サーバー構築だの調査だののなんだかんだの都合で同僚のマシンさわって設定やら環境変数やら覗くことが多いのですが、 そのとき.profileやら.bashrcなどシェル(bash)の設定がほぼいじられてないままで使ってたりしてつらいなと思うわけです。
もうちょっと色々設定を弄って楽にしたほうがいいぞよと話をしつつ、 どうせ弄ってないんだし俺の好きに設定していいよねと勝手にalias追加したり環境変数設定したりさせてもらってますが、 そもそも自分のマシンなのだから自分の好みにいじったほうが幸せなはずです。
とはいうものの0から.profileなど弄ったりするのも なにをどう設定すればいいのかわからん というのも事実。
なのでbashの設定をいい感じにしてくれるフレームワーク(でいいのかな…)の Bash it を使ってみましょう。
Bash itとは
Bash it は 別の記事で説明しますがzshにおける oh-my-zsh のように bashの設定をいい感じに提供してくれるフレームワークです。
特定のツールむけの機能を拡張する plugin 、画面表示設定を変更できる theme などを 自分好みの設定を追加で設定することができます。
さっそく試してみましょう。 今回試すために用意した環境は Ubuntu 14.04 server 、ユーザー名は bash-it です。
インストール
インストール方法はGitHubのREADMEに書いてあるとおり、
- bash-itをcloneする
- インストールシェルを起動する
だけです。
bash-it@vagrant-ubuntu-trusty-64:~$ git clone https://github.com/revans/bash-it.git ~/.bash_it
Cloning into '/home/bash-it/.bash_it'...
...
インストールシェルを起動すると .bash_profile をリネームして保持してくれます。 その後色々設定したい内容を聞いてくるのでよしなに回答をするだけです。
bash-it@vagrant-ubuntu-trusty-64:~$ ~/.bash_it/install.sh
Your original .bash_profile has been backed up to .bash_profile.bak
Copied the template .bash_profile into ~/.bash_profile, edit this file to customize bash-it
Do you use Jekyll? (If you don\'t know what Jekyll is, answer 'n') [Y/N] n
Jekyllはとりあえず n
で…。
次にaliasを設定するか聞いてきます。
all
を回答するとすべてのaliasが定義されるわけですが、
設定したぶんbashの起動が遅くなってしまうので
自分が使っているツールのaliasだけ設定できる some
を回答し、
設定したいaliasにそれぞれ y
を回答するほうがいいでしょう、
alias一覧 を参照して どのようなaliasが設定されるのか確認しておくとより幸せになれそうです。
Would you like to enable all, some, or no aliases? Some of these may make bash slower to start up (especially completion). (all/some/none) some
Would you like to enable the bundler aliases? [Y/N] y
Would you like to enable the emacs aliases? [Y/N] n
Would you like to enable the general aliases? [Y/N] y
Would you like to enable the git aliases? [Y/N] y
Would you like to enable the gitsvn aliases? [Y/N] n
Would you like to enable the heroku aliases? [Y/N] y
...
次にpluginの設定です。これもalias同様自分が使っている、使いたいツールにあわせたpluginを設定しましょう。
plugin一覧 をみておきましょう。
Would you like to enable all, some, or no plugins? Some of these may make bash slower to start up (especially completion). (all/some/none) some
Would you like to enable the base plugins? [Y/N] y
Would you like to enable the battery plugins? [Y/N] n
Would you like to enable the browser plugins? [Y/N] n
Would you like to enable the chruby-auto plugins? [Y/N] n
Would you like to enable the chruby plugins? [Y/N] n
...
最後にcompletion(補完)の設定です。これはかなり重要です。 補完があるないの違いで 作業速度と快適度が激しく変わる からです。
completion一覧 をみておきましょう。
Would you like to enable all, some, or no completion? Some of these may make bash slower to start up (especially completion). (all/some/none) some
Would you like to enable the bash-it completion? [Y/N] y
Would you like to enable the brew completion? [Y/N] n
Would you like to enable the capistrano completion? [Y/N] n
Would you like to enable the conda completion? [Y/N] n
Would you like to enable the defaults completion? [Y/N] n
Would you like to enable the django completion? [Y/N] n
Would you like to enable the drush completion? [Y/N] n
Would you like to enable the fabric-completion completion? [Y/N] n
...
さて、インストールシェルが終了したら設定を再読み込み(またはログアウト、ログイン)しましょう。
source ~/.bash_profile
これで見た目ががらっとかわります。
これがこうなりました。
テーマを変更する
さすがにデフォルトのテーマを見たら なんだこれ と今までの表示と違いすぎて面くらうでしょう。
なのでテーマを変更します。
.bash_profile
の BASH_IT_THEME を指定している部分を編集します。
今回は pure を指定してみました。
export BASH_IT_THEME='pure'
また設定を再読込すると表示が変わります。
theme一覧 に利用できるテーマが登録されています。 自分好みのテーマを探しましょう。
おわり
Bash itを使うことでシェルをいい感じに初期設定をしてくれました。 これを元にして自分好みの設定をカスタマイズしていき、快適な環境を作っていきましょう。