zshå ¥éãã¦ã¿ãã便å©ããã¦é¼»æ¯ãæããããªã
ãã·ã§ã«ï¼ã¿ã¼ããã«ã§ã³ãã³ãå©ãã ãã§ãããããã©ã«ãã®bashã§ååã
ããæã£ã¦ããåã§ããã漢のzshãè¦ã¦èãã180度å¤ããã¾ãããzshã¹ã´ã¤ãæãã¦ãã
zshã¯ã©ãã«ãæ
å ±ãå¾ã«ããã¦æ¬é ãã¦ãããã©*1ãæ¼¢ã®zshã¯åãããããã¦ç´ æ´ãããï¼åãæ¼¢ã¨ãã¦ã®ç¬¬ä¸æ©ãè¸ã¿åºããããªæ°ããã¦ãã¾ããã
é£è¼ã®5åã¾ã§èªãã§ãã£ã¦ã¿ãã®ã§ãè¨é²ãã¦ããã¾ãã
ã¾ãã¯bashã«ãå¥ã
æåã¯ã¿ã¼ããã«ã§zshãå©ãã¦è©¦ãã¦ããã©ãããã°ããã»ã©ããã©ã«ãã§è¯ãããããªããããããããããã©ã«ãã§ãé¡ããã¾ããã¨ããæ°æã¡ãå¼·ããªã£ãã®ã§ããã°ã¤ã³ã·ã§ã«ãå¤æ´ããããªãbashãä»ã¾ã§ãããã¨ãã
$ chsh -s /bin/zsh
ããã§ã次å以éã¯æåããzshã使ãã¾ãã
ã¨ããã§zshã£ã¦ä½ã¦èªãã®ï¼
ããã£ã¨ããããã§æ£ããã¯ãï¼
Z Shell - Wikipedia
æ¼¢ã®éç¨
.zshrcãä½ããbashã®è¨å®ãå¼ãç¶ã
zshã¯è¨å®ã.zshrcã«æ¸ãã
ãã¼ã ãã£ã¬ã¯ããªã«.zshrcãã¡ã¤ã«ãä½ãã.bashrcã.bash_profileã«æ¸ãã¦ããè¨å®ãé©å®ã³ãã¼ã丸ãã¨ã³ãã¼ã§ãããã®ããªï¼
ãã¨ã¯ã.zshrcã«ã´ãªã´ãªè¨å®ãæ¸ãã¦è奮ãã¾ããã°ããï¼
.zshrcã®ç·¨éã¨èªã¿è¾¼ã¿
.zshrcãç·¨éãããã
% source ~/.zshrc
ã§å度èªã¿è¾¼ããã¨ãã§ããã
è£å®æ©è½
# è£å®æ©è½ autoload -U compinit compinit
ããã§ãè£å®æ©è½ã使ãããTabã§ã³ãã³ãåããªãã·ã§ã³ãªã©ãè²ã è£å®ã§ããï¼
ããã³ãã
【コラム】漢のzsh (2) 取りあえず、プロンプトを整えておく。カッコつけたいからねã®ä¾ã¨ã»ã¨ãã©åãã
# ããã³ããã®è¨å® case ${UID} in 0) PROMPT="%{^[[31m%}%n%%%{^[[m%} " RPROMPT="[%~]" PROMPT2="%B%{^[[31m%}%_#%{^[[m%}%b " SPROMPT="%B%{^[[31m%}%r is correct? [n,y,a,e]:%{^[[m%}%b " [ -n "${REMOTEHOST}${SSH_CONNECTION}" ] && PROMPT="%{^[[37m%}${HOST%%.*} ${PROMPT}" ;; *) PROMPT="%{^[[31m%}%n%%%{^[[m%} " RPROMPT="[%~]" PROMPT2="%{^[[31m%}%_%%%{^[[m%} " SPROMPT="%{^[[31m%}%r is correct? [n,y,a,e]:%{^[[m%} " [ -n "${REMOTEHOST}${SSH_CONNECTION}" ] && PROMPT="%{^[[37m%}${HOST%%.*} ${PROMPT}" ;; esac
ä¸è¨è¨å®ã®"^["ã¯æååã§ã¯ãªãã¨ã¹ã±ã¼ãè¨å·ãªã®ã§ããã®ã¾ã¾ã³ããããã¨åããªãã
Emacsãªããç½®æ対象ã"^["ãç½®ææåã"C-q ESC"ã§å¤æããã¨åãã
ããã³ããããã¦ã¼ã¶ã¼å% ãã«ãªã£ã¦ãã¦ãç¾å¨ã®ãã¹ãå³å´ã«è¡¨ç¤ºããããã«ããã
ãã¹ãå³å´è¡¨ç¤ºã«ããã¨ãå·¦ããã³ããã®é·ããä¸å®ã«ãªã£ã¦ããããªã«ãã«å¿«é©ï¼
ã³ãã³ãå±¥æ´
æå®ãããã¡ã¤ã«ã«ãå®è¡ããã³ãã³ãã®å±¥æ´ãè¨é²ããããéè¤ãããã®ã¯è¨é²ããªãããä¸åº¦å ¥åããã³ãã³ãã¯å¾è¿°ã®å±¥æ´æ¤ç´¢ãããã¹ã¦è¾¿ããããã«ãªããããããzshï¼
# ã³ãã³ãå±¥æ´ HISTFILE=~/.zsh_history HISTSIZE=6000000 SAVEHIST=6000000 setopt hist_ignore_dups # ignore duplication command history list setopt share_history # share command history data
ã³ãã³ãå±¥æ´æ¤ç´¢
以ä¸ã®è¨å®ã§ãã³ãã³ãã®å±¥æ´ãæ¤ç´¢ã§ããã
# ã³ãã³ãå±¥æ´æ¤ç´¢ 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
Ctrl-P/Ctrl-Nã§ãå
¥åä¸ã®æåããå§ã¾ãã³ãã³ãã®å±¥æ´ã表示ãããã"l"ã¨å
¥åããç¶æ
ã§Ctrl-Pãæ¼ãã¨ã"ls"ã"less"ã次ã
ã«è¡¨ç¤ºããã¦ããã
bashã ã¨"!hoge"ã§hogeããå§ã¾ãæå¾ã®ã³ãã³ããå®è¡ã§ãããã©ã使ãåæãæªãã£ããzshã®ãã®è¨å®ã®æ¹ãç¡çããªãã¦ç´ æµã§ããï¼
ãã®ä»ãããã
# ãã£ã¬ã¯ããªåãå ¥åããã ãã§ç§»å setopt auto_cd
"cd"ãå
¥åããªãã¦ã移åã§ããããã«ãªãï¼
"~"ã¨ã".."ã¨ã ãæã¦ã°åããã®ã¯ããããããã
# 移åãããã£ã¬ã¯ããªãè¨é²ãã¦ããã"cd -[Tab]"ã§ç§»åå±¥æ´ãä¸è¦§ setopt auto_pushd
"cd -[Tab]"ã§ã移åå±¥æ´ã表示ãããããã«ãªãã
ã²ã¨ã¤åã«ãããã£ã¬ã¯ããªã«æ»ããããã©ããã¹ãé·ãã¦é¢åã»ã»ã»ã¨ããæã«å¹æ絶大ï¼
# ã³ãã³ãè¨æ£ setopt correct
ã³ãã³ããæã¡ééããæã«ãè¿ãã³ãã³ããææ¡ãã¦ããããä½ãã®ä¾¿å©æ©è½ãè³¢ãããï¼
# è£å®åè£ãè©°ãã¦è¡¨ç¤ºãã setopt list_packed
Tabã§è£å®åè£ã表示ããéãç»é¢ã«åã¾ããªãå ´åã¯è¡¨ç¤ºééãè©°ãã¦ãªãã¹ãåã¾ãããã«ãã¦ããããç´°ããã¨ããã§æ°ãå©ãã¦ããªããã
# è£å®åè£è¡¨ç¤ºæãªã©ã«ãããã¨ãã¼ãé³ããªããªãããã«è¨å® setopt nolistbeep
ãã¼ãé³´ãã¾ããã¨çµæ§ã¹ãã¬ã¹ãªã®ã§ãè¨å®ãã¦ããã¾ãã
# Emacsã©ã¤ã¯ãã¼ãã¤ã³ãè¨å® bindkey -e
æåããEmacs風ãã¼ãã¤ã³ãã ã¨æããã ãã©ãªï¼ãã¡ããããããè¨å®ã
vim使ãã«ã¯vim風ãã¼ãã¤ã³ãè¨å®ãããã¾ããï¼
zshã¯ãããã®ã
ã¾ã å
¨ç¶ç解ã§ãã¦ãã¾ããããã¨ã¦ã使ããããã¨ãããã¨ã¯åããã¾ããã
è²ã
ã¨èª¿ã¹ã¦ããã£ã¨ä½¿ãããªããããã«ãªãããã§ãï¼
*1:ããããã·ã§ã«ãããã£ããå¤ãããã¨ãããã¨ããªãã£ã