How to install zsh (with .zshrc customization)

I've been using fish for a long time, but now I've switched to zsh for a change! This time, I will write about ** how to install zsh ** and **. Customize zsh with zshrc **.

What you can do with the settings in this article

--Powerful completion of zsh --The following syntax highlighting like fish

How to install zsh

Use the brew command to download zsh and the plugin used this time. Execute the following command.

$ brew install zsh

$ brew install zsh-completions
=>Complementary enhancement plugin

$ brew install zsh-autosuggestions
=>Plugin that displays the prediction at the time of input completion in the shadow

$ brew install zsh-syntax-highlighting
=>A plugin that syntax highlights your input

After executing the above

$ zsh

When you start zsh with

You will be asked for input with the above 3 choices, so select 0 and enter (.zshrc will be generated automatically)

Change login shell

$ sudo vi /etc/shells
Password:

After executing the above, add the following and save

/usr/local/bin/zsh

qiita.png

chsh -s /usr/local/bin/zsh

Do the above and change the login shell

Editing .zshrc

With the settings so far, .zshrc should be generated in your home directory.

vi .zshrc

Execute the above and copy and save the following

#interpolation
autoload -U compinit
compinit
#Character code
export LANG=ja_JP.UTF-8
#prompt
autoload -U colors
colors

#History
#Specify the file to save the history
HISTFILE="$HOME/.zsh_history"
#Number of history
HISTSIZE=100000
SAVEHIST=100000
#Do not save duplicate history
setopt hist_ignore_dups
#Share history
setopt share_history
#If you put a space at the beginning, it will not be recorded in the history
setopt hist_ignore_space
#Search history
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^P" history-beginning-search-backward-end
bindkey "^N" history-beginning-search-forward-end 
#cd settings
#Move by directory name only.
setopt auto_cd
#Pushd automatically
setopt auto_pushd
#No pushd history is left.
setopt pushd_ignore_dups
#Terminal title
case "${TERM}" in
kterm*|xterm)
    precmd() {
        echo -ne "\033]0;${USER}@${HOST}\007"
    }
    ;;
esac 
#Fixed command mistake
setopt correct
#Make the choice of complement easier
zstyle ':completion:*' menu select
#Only if there is no candidate in the current directory, the directory on cdpath is suggested.
zstyle ':completion:*:cd:*' tag-order local-directories path-directories
#cd does not select the current directory from the parent directory, so hide it(Example: cd ../<TAB>):
zstyle ':completion:*:cd:*' ignore-parents parent pwd
#Display completion candidates as close as possible
setopt list_packed
#Color settings
export LSCOLORS=Exfxcxdxbxegedabagacad
#Color setting at the time of completion
export LS_COLORS='di=01;34:ln=01;35:so=01;32:ex=01;31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
autoload -U colors ; colors ; zstyle ':completion:*' list-colors "${LS_COLORS}"

#alias
case "${OSTYPE}" in
freebsd*|darwin*)
  alias ls="ls -GF"
  ;;
linux*)
  alias ls="ls -F --color"
  ;;
esac
#ALC search with w3m
function alc() {
  if [ $# != 0 ]; then
    w3m "http://eow.alc.co.jp/$*/UTF-8/?ref=sa"
  else
    w3m "http://www.alc.co.jp/"
  fi
}
#A function that automatically hits ls when you hit cd
function cd(){
    builtin cd $@ && ls;
}
#Other
#Key binding
bindkey -e
#Don't beep
setopt nobeep
#editor
export EDITOR=emacs
#Prevent prompts from overwriting output without line breaks
unsetopt promptcr
#Load individual settings
[ -f ~/.zshrc.mine ] && source ~/.zshrc.mine
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
#git settings
autoload -Uz vcs_info
setopt prompt_subst
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:git:*' stagedstr "%F{yellow}!"
zstyle ':vcs_info:git:*' unstagedstr "%F{red}+"
zstyle ':vcs_info:*' formats "%F{green}%c%u[%b]%f"
zstyle ':vcs_info:*' actionformats '[%b|%a]'
# -----------------------------
# Prompt
# -----------------------------
# %M host name
# %m host name
# %d Current directory(full path)
# %~Current directory(Full pass 2)
# %C current directory(Relative path)
# %c current directory(Relative path)
# %n Username
# %#User type
# %?Return value of the previous command
# %D date(yy-mm-dd)
# %W date(yy/mm/dd)
# %w date(day dd)
# %*time(hh:flag_mm:ss)
# %T time(hh:mm)
# %t time(hh:mm(am/pm))
# PROMPT='[%n][%c]'\$vcs_info_msg_0_' $ '
PROMPT='%B%F{32}~/%C%f'\$vcs_info_msg_0_' $ '
#'di=01;34:ln=01;35:so=01;32:ex=01;31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
precmd(){ vcs_info }

After saving above

source .zshrc

Reflect the setting with.

Supplement

You can customize zsh to your liking by editing .zshrc.

Please try various things.

Recommended Posts

How to install zsh (with .zshrc customization)
How to install python-pip with ubuntu20.04LTS
How to install mysql-connector with pip3
How to install Anaconda with pyenv
How to install python3 with docker centos
How to install Python
How to install pip
How to install archlinux
How to install python
How to install BayesOpt
How to install Nbextensions
How to install Prover9
How to install OpenGM on OSX with macports
[2020.8 latest] How to install Python
How to install Python [Windows]
Tabpy 1.0 (2020-01 version) How to install
How to update with SQLAlchemy?
How to cast with Theano
How to install mkl numpy
How to Alter with SQLAlchemy?
How to separate strings with','
How to install Pelican blog
How to RDP with Fedora31
How to install poetry (error handling) in zsh environment
How to Delete with SQLAlchemy?
How to install NPI + send a message to line with python
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to install Theano on Mac OS X with homebrew
How to install python using anaconda
Python: How to use async with
How to install mysql-connector-python on mac
How to install and use Tesseract-OCR
What to do with Magics install
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install graph-tool on macOS
How to install wkhtmltopdf (Amazon Linux2)
How to deal with imbalanced data
How to install VMware-Tools on Linux
How to install pycrypto on Windows
How to install OpenCV on Mac
How to install MBDyn (Linux Ubuntu)
How to install PyPy on CentOS
How to get started with Scrapy
Easy to install pyspark with conda
How to get started with Python
How to install TensorFlow on CentOS 7
How to deal with DistributionNotFound errors
How to install and configure blackbird
How to get started with Django
How to install CUDA and nvidia-driver
How to install and use Graphviz
Unable to install Python with pyenv
How to use FTP with Python
How to calculate date with python
How to install Go on Ubuntu
How to install music 21 on windows
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to automatically install Chrome Driver for Chrome version with Python + Selenium + Chrome
How to do arithmetic with Django template