LoginSignup
11
12

More than 5 years have passed since last update.

bashからzshに移行してみた!(mac)

Last updated at Posted at 2018-05-20

ちょっとまだあまりよくわかっていないのですが、
bashよりzshの方が良いというのを聞いたので、早速使ってみました。

1. homebrewでzshをインストール

まずはインストールします。

$ brew install zsh

そして、/etc/shellsに以下のコードを追記します。

/usr/local/bin/zsh

そして、zshを使うよ〜〜って指示を出します。

$ chsh -s /usr/local/bin/zsh

ちなみに、僕は2番目の手順をせずに、zshを使うよ〜〜〜って言い始めたので、コンピュータに怒られました。
その時のエラーがこれ

chsh: /usr/local/bin/zsh: non-standard shell

これが出たら、2番目を忘れている可能性大ですので、やってみてくださいね。

環境設定

一回ターミナルを再起動すると、もうzshに切り替わっています!
さてさて、
なんか出ていますねえ。

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

--- Type one of the keys in parentheses ---1

要は、
0 => 環境設定について何もせずに終了
1 => 環境設定について、.zshrcファイルを作って終了。ちなみにこのファイルに設定とか書くみたい
2 => 環境設定を対話形式で進めていくよ〜

僕は1にしました。

3.プラグインマネージャーzgenを入れてみる。

社員さんにzgenがrecommendと言われたので、入れてみます。

zgenについては、個人ブログですが、これが分かりやすいかも、、、
zshのプラグインマネージャzgenについて

3-1. zgenを入れます。

まずは、zgenのgithubに行きましょう。
zgenのgithub

そして、README.mdを確認します。
お、インストール方法かいてるじゃん〜

README.mdにもかいていますが、同じことをつらつら言います。
まずはクローン

git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen"

.zshrcをロードします

source "${HOME}/.zgen/zgen.zsh"

自分のテキストエディタ(僕はatom)で.zshrcを開く

atom .zshrc

これを追記

# if the init scipt doesn't exist
if ! zgen saved; then

  # specify plugins here
  zgen oh-my-zsh

  # generate the init script from plugins above
  zgen save
fi

で、もう一回.zshrcをロードする

source .zshrc

なんかできた。
まだあまりよくわかっていないですが、なんかできました。

(追記)bashの設定をzshにも適用する

bashでwebpackやgrep -rコマンドが使えていたのに、zshで使えなくなりました。
なんでや!って思って、teratailで質問。そうしたら、bashの設定をzshにコピペしていないからだということが判明。

確かに、bashの設定は「.bash_profile」や「.bashrc」から読み込みますが、zshの設定は「.zshrc」から読み込むので、移さないといけなかった。。。
というわけで、bashの設定をzshの設定にコピペしましょう!

11
12
0

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
11
12