zshãtcshãªãã¼ãã¤ã³ãã§
ãã°ã¤ã³ã·ã§ã«ã¨ãã¦ã¯ããåä½å¹´ã tcsh ããã£ã¨ä½¿ã£ã¦æ¥ã¦ããã®ã§ãããAll about Ruby on Rails & Data recovery software ãç´ ç´ã«åä½ãããã®ãé£ããã£ãã®ã§ zsh ã¸ç§»è¡ãããã¨ã決æãã¾ãã*1ã
【連載】漢のzsh | マイナビニュースãåèã«ãã¦ã ãããã¯éåæãªã移è¡ã§ããã®ã§ãããæå¾ã¾ã§ãªããªã馴æã¾ãªãã£ãã®ããã¼ãã¤ã³ãã£ã³ã°ã§ããã
æè¿ãããã tcsh ã¨ã»ã¼åãæãã«ãªã£ã¦ããã®ã§ãã©ãè¨å®ããã®ãã以ä¸ã«ã¡ã¢ãã¦ããã¾ãã
åºæ¬ã¯ Emacs ãã¤ã³ãã£ã³ã°
tcsh ã¯åºæ¬çã« emacs ã£ã½ããã¼ãã¤ã³ããªã®ã§ãã¾ãã¯å ¨ä½çã« emacs ã£ã½ããã¾ããã
bindkey -e
M-p 㨠M-n ãå¤æ´
tcsh ã® M-p 㨠M-n ã«ã¯ã«ã¼ã½ã«ããå·¦å´ãä¸è´ããå±¥æ´ãã©ãã©ã表示ããæ©è½ãå²ãå½ã¦ããã¦ãã¾ãããã㧠zsh ã§ã¯ä»¥ä¸ã®ããã«ãã¾ããã
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
M-f ã M-b ãªã©ã®åèªãæ±ãæ©è½ã®èª¿ç¯
ãã®æ©è½ãä¸çªã®ããè ã§ãããçµè«ããè¨ãã°ã以ä¸ã ~/.zshrc ã«æ¸ãã
autoload -Uz select-word-style select-word-style default zstyle ':zle:*' word-chars '*?_-.[]~=' fpath=( ~/.home/zsh $fpath ) autoload -Uz tcsh-forward-word-match zle -N forward-word tcsh-forward-word-match
以ä¸ã ~/.home/zsh/tcsh-forward-word-match ã«æ¸ãã¾ããã
# modified from /usr/share/zsh/4.3.12/functions/forward-word-match emulate -L zsh setopt extendedglob autoload -Uz match-words-by-style local curcontext=":zle:$WIDGET" word local -a matched_words integer count=${NUMERIC:-1} if (( count < 0 )); then (( NUMERIC = -count )) zle ${WIDGET/forward/backward} return fi while (( count-- )); do match-words-by-style # For some reason forward-word doesn't work like the other word # commands; it skips whitespace only after any matched word # characters. # if [[ -n $matched_words[4] ]]; then # # just skip the whitespace # word=$matched_words[4] # else # # skip the word and trailing whitespace # word=$matched_words[5]$matched_words[6] # fi if [[ -n $matched_words[4] ]]; then # skip the whitespace and the word word=$matched_words[4]$matched_words[5] else # jist skip the word word=$matched_words[5] fi if [[ -n $word ]]; then (( CURSOR += ${#word} )) else return 1 fi done return 0
M-f M-b ã®åã·ã§ã«ã®åä½
ä¸è¨ã®è¨å®ã®æå³ã®è§£èª¬ãããåã«ãã¾ã㯠tcsh, bash, zsh ã§ã®åä½ã確èªãã¦ããã¾ãã(以ä¸ã§ã¯ã«ã¼ã½ã«ä½ç½®ã¯ã¹ã¿ã¤ã«ã·ã¼ãã® background-color ã§è¡¨ç¾ãã¦ããã¾ãã®ã§ãRSS ãªã¼ãã¼ã§ã覧ã®å ´åã«ã¯è¦ããªãããããã¾ãã)
tcsh ã®å ´å M-f ãæ¼ããã³ã«æ¬¡ã®ããã«ã«ã¼ã½ã«(赤ãåè§)ã移åãã¾ãã
% ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin
éã« M-b ãæ¼ããã³ã«æ¬¡ã®ããã«ã«ã¼ã½ã«ã移åãã¾ãã
% ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin
M-f 㨠M-b ã§ã¯åæ¢ä½ç½®ãå¾®å¦ã«éãã¨ããããã¤ã³ãã§ãã
bash ã®å ´å M-f ã®åä½ã¯ tcsh ã¨å ¨ãåãã§ãã
$ ls -l /usr/bin $ ls -l /usr/bin $ ls -l /usr/bin $ ls -l /usr/bin $ ls -l /usr/bin
ããã M-b ã®åä½ã¯ -l
ã®ç®æã®åæ¢ä½ç½®(éãåè§)ã tcsh ã¨ã¯ç°ãªãã¾ãã
$ ls -l /usr/bin $ ls -l /usr/bin $ ls -l /usr/bin $ ls -l /usr/bin $ ls -l /usr/bin
zsh ã select-word-style bash ã§åä½ãããå ´åã¯ãM-f ã®åä½ã¯æ¬¡ã®ããã«ãªãã¾ãã
% ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin
bash ã®åä½ã¨ã¯å ¨ãç°ãªãã¾ããéã« M-b ãæ¼ããå ´åã¯æ¬¡ã®ããã«ãªã bash ã®åä½ã¨ä¸è´ãã¾ãã
% ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin
ã¾ããM-f ã§ã®åæ¢ä½ç½®ã¨ M-b ã®åæ¢ä½ç½®ãä¸è´ãã¦ãã¾ãã
zsh ã select-word-style default ã§åä½ãããå ´åã¯ãM-f ã®åä½ã¯æ¬¡ã®ããã«ãªãã¾ãã
% ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin
åå¼æ°ã®æåã®æåã«åæ¢ãã¾ããM-b ãæ¼ããæãåæ¢ä½ç½®ã¯åãã§ãã
% ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin % ls -l /usr/bin
M-f M-b 解説
ã³ãã³ãã©ã¤ã³ãæ§æããæåã¯åèªãæ§æããæå(w
ã¨ãã)ã¨åèªãæ§æããªãæå(.
ã¨ãã)ã®2種é¡ã«ããããã¨ãã§ãã¾ãã
ãã㨠tcsh 㨠bash ã®å ´åã®ã«ã¼ã½ã«ãåæ¢ããä½ç½®ã¯ã
- M-f ã®å ´åã¯ã«ã¼ã½ã«ããå³å´ã®
w
ã¨.
ã®å¢ç® (www...
) - M-b ã®å ´åã¯ã«ã¼ã½ã«ããå·¦å´ã®
.
ã¨w
ã®å¢ç® (...www
)
ã¨ãªãã¾ãã
zsh ã®å ´åã¯ã
- M-f ã®å ´åã¯ã«ã¼ã½ã«ããå³å´ã®
.
ã¨w
ã®å¢ç® (...www
) - M-b ã®å ´å㯠tcsh, bash ã¨åã
ã¨ãªãã¾ãã
ããã¦åèªãæ§æããæåã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã
tcsh | [:alnum:] 㨠'*?_-.[]~=' |
bash | [:alnum:]*2 |
zsh 㧠select-word-style bash | [:alnum:] |
zsh 㧠select-word-style default | [:alnum:] 㨠'*?_-.[]~=/&;!#$%^(){}<>' |
ããã§ãã¾ã㯠zsh ã®åèªãæ§æããæåã tcsh ã¨ä¸è´ãããããã«æ¬¡ã®ãããªè¨å®ããã¾ããã
autoload -Uz select-word-style select-word-style default zstyle ':zle:*' word-chars '*?_-.[]~='
select-word-style default æ㯠word-chars ã«è¨å®ããæåã«å ã㦠[:alnum:] ãåèªãæ§æããæåã«ãªãã¾ãã®ã§ããã㧠tcsh ã¨ä¸è´ãã¾ãã
ãã㦠M-f ã®æã®åä½ãå¤æ´ããããã«æ¬¡ã®ãããªè¨å®ããã
fpath=( ~/.home/zsh $fpath ) autoload -Uz tcsh-forward-word-match zle -N forward-word tcsh-forward-word-match
~/.home/zsh/tcsh-forward-word-match ãä½æãã¾ãããtcsh-forward-word-match ã¯ã«ã¼ã½ã«ããå³å´ã® w
㨠.
ã®å¢ç® (www...
) ã¸ã«ã¼ã½ã«ã移åãããé¢æ°ã§ãã
ããã§ãããã tcsh ã¨ã»ã¼åãæãã§åä½ããããã«ãªãã¾ããã
*1:C Shell ç³»ã§ã¯ãªã Bourne Shell ç³»ã®ã·ã§ã«ã使ãããã¨ãã£ã¨æã£ã¦ããã¨ããã®ãããã¾ã
*2:æªç¢ºèªã§ãããããããããªã£ã¦ãã¾ã