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 **.
--Powerful completion of zsh --The following syntax highlighting like fish
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)
$ sudo vi /etc/shells
Password:
After executing the above, add the following and save
/usr/local/bin/zsh
chsh -s /usr/local/bin/zsh
Do the above and change the login shell
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.
You can customize zsh to your liking by editing .zshrc
.
Please try various things.
Recommended Posts