3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Zshの導入

Posted at

zshとは

ログインシェルの一つ.
標準のログインシェルはbashだが,bashと比べて補完機能が強力だったり,ディレクトリ移動がいろいろと便利だったりするらしい.
導入してみたので,ログとして.

zshの導入

zshのインストール

Mac

brew install --without-etcdir zsh
brew install zsh-completions

Ubuntu

sudo apt install zsh

Ubuntuのzsh-completionsについては後日.

ログインシェルの変更

このまま zsh と打てばzshのシェルを使用できるが,毎回 zsh を入力しなければいけないので,ログインシェルを変更する.

次の作業の前に which zsh でzshのディレクトリを確認しておくと安心

Mac

sudo vim /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

一番下に先程 which zsh で取得したパスを入力する
標準では /usr/local/bin/zsh
最後に以下のコマンドを入力.ただしディレクトリはzshのディレクトリ

chsh -s /usr/local/bin/zsh

Ubuntu

chsh を入力すると以下のようなメッセージが表示されるので,先程 which zsh で取得したパスを入力

Changing the login shell for root
Enter the new value, or press ENTER for the default
    Login Shell [/bin/bash]:

zshの設定

zshの設定は基本的に.zshrcに記入する
主なものを列挙

# 余分な空白は詰めて記録
setopt HIST_IGNORE_SPACE
# ヒストリファイルを上書きするのではなく、追加するようにする
setopt APPEND_HISTORY
# 履歴がいっぱいの時は最も古いものを先ず削除
setopt HIST_EXPIRE_DUPS_FIRST
# 履歴検索中、重複を飛ばす
setopt HIST_FIND_NO_DUPS
# 前のコマンドと同じならヒストリに入れない
setopt HIST_IGNORE_DUPS
# history コマンドをヒストリに入れない
setopt HIST_NO_STORE
# 履歴から冗長な空白を除く
setopt HIST_REDUCE_BLANKS
# 履歴を共有
setopt SHARE_HISTORY
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?