LoginSignup
14
24

More than 1 year has passed since last update.

zsh 設定

Last updated at Posted at 2017-04-16

かっこいいものを使いたい。bash→zshに変更する!!
インスコは省略します。

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

[http://blog.tokoyax.com/entry/zsh/bash-to-zsh]

/usr/local/bin/zsh にインストールされた最新版のzshを使うための設定をしていきます。

2022/9/24追記
Apple Silicon Mac では Homebrew のインストール先が /opt/homebrew 以下となっています。

インストールされているシェルとそのパスを確認します。

$ 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

/usr/local/bin/zsh を追加しましょう。

2022/9/24追記
/opt/homebrew/bin/zsh を追加しましょう

$ sudo vi /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
/opt/homebrew/bin/zsh

ログインシェルを変更します。

$ chsh -s /opt/homebrew/bin/zsh
…パスワード入力

[ -s ] オプション :変更するシェルを指定する

これで、ターミナルを起動するとzshが起動するようになります。

zshrc

ひとまずの設定はこちら
色々参考にさせてもらいました。
全然使いこなせてないので、最低限にしておく。

# Lines configured by zsh-newuser-install
export EDITORP=vim #エディタをvimに設定
export LANG=ja_JP.UTF-8 #文字コードをUTF-8に設定

# プロンプト設定
PROMPT='[%~:%n] %# '

# history
HISTFILE=~/work/dotfils/zsh/.zsh_hist
HISTSIZE=1000
SAVEHIST=1000
setopt extended_history #ヒストリに実行時間も保存
setopt hist_ignore_dups #直前と同じコマンドはヒストリに追加しない

#vi ライクな操作ができる
bindkey -v
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall

autoload -Uz compinit
compinit

#
# setopt
#

# cdした先のディレクトリをディレクトリスタックに追加
setopt auto_pushd

# pushdしたとき、ディレクトリがすでにスタックに含まれていればスタックに追加しない
setopt pushd_ignore_dups

# コマンドのスペルを訂正する
setopt correct

# <Tab>でパス名の補完候補を表示したあと、
# 続けて<Tab>を押すと候補からパス名を選択することができるようになる
zstyle ':completion:*:default' menu select=1

autoload colors
zstyle ':completion:*' list-lolors "${LS_COLORS}"


#エイリアス
alias la='ls -aG'
alias ll='ls -lG'
alias vz='vim ~/work/dotfiles/zsh/.zshrc'

# cdの後にlsを実行
chpwd() { ls -ltrG  }

# 補完候補のメニュー選択で、矢印キーの代わりにhjklで移動出来るようにする。
zmodload zsh/complist
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char


# End of lines added by compinstall

zshenv

# zshが起動した際に必ず読み込まれる設定ファイル
# 主に環境変数などの、操作に関係ない設定を記述

export ZDOTDIR=$HOME/work/dotfiles/zsh/


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