LoginSignup
11
9

More than 5 years have passed since last update.

zsh入れてみた

Last updated at Posted at 2017-12-19

せっかくMacbookPro買ったので
今までbashしか触ってこなかったが導入してみたのでメモ

環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.2
BuildVersion:   17C88

まずはインストール 

※要Homebrew

$ brew install zsh
$ brew install zsh-completions
  • zsh-completionsは、zshの補完機能を強化するプラグイン

ログインシェルの変更

当然だがデフォルトではbashが起動するので以下手順で変更する

ログインシェルのリストにzshを追加

/etc/shellsに利用可能なログインシェルのリストが記述されている。
デフォルトは多分こんな感じで記載されている。

$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

以下コマンドで今インストールしたzshを追加する

$ sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells"

ログインシェルを変更する

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

パスワードを聞かれるので入力してシェルを再起動するとzshが立ち上がる。

初期設定

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

要するに…

  • qを入力すると、何もせずユーティリティは終了する(次にzshを起動したときにまた立ち上がる)
  • 0を入力すると、ホームディレクトリに.zshrcを作成して終了(中身は空っぽ)
  • 1を入力すると、.zshrc設定を対話型で行う

使ったことはないのでよく分からないがどうやら1の対話型の設定はあんまり使い勝手がよくなさそうなので、0を入力した。
すると以下のように.zshrcが作成された

% cat .zshrc
# Created by newuser for 5.4.2

とりあえずzshのここがすごい

とりあえず補完機能がすごい。とりあえずどこ見てもこれ.zshrcに入れとけ感。

~/.zshrc
# 補完機能
autoload -Uz compinit
compinit

こいつをsourceしてあげて「ls -」まで打ってTabキーを押してみたらすごさが2秒でわかる。
今までmanとか--helpとか打ってたのがアホらしくなる。

その他設定について

  • aliasとかPATHとか基本的には.bash_profileとかに書いてる設定は同じように書いて使える
  • その他先人たちが練り上げてきた設定を頂いてけばもっと幸せになれるらしい

続きは気が向いたら更新します。

参考URL

macでbashからzshへ乗り換えた話
15分でわかる zsh
とりあえずZshを使えば良いんだろう?

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