Kamuycikap - SentenceDataBase

日々の勉強の記録を気分で書き綴るブログ

Windows7にもzsh環境を

普段、家で楽しんでいるのはUbuntuLinux。
会社ではWindows7とUbuntuLinux。
こんな環境なので、エディタもxyzzyとEmacs23。
当然、シェルもPowerShellではなくzshにしたい。

Cygwinインストール

様々なサイトで紹介されているので割愛します。
Cygwinのサイトに行って、インストーラーをダウンロードし実行するだけ。
私の環境では、「setup.exe」を実行するだけでOKでした。
注意するべき点は、デフォルトではzshはインストールされないので、インストールするパッケージを選択する段階で忘れずにzshをチェックしておく事。

Windows7で実行できるようにごにょごにょ

Windows7ではzshを実行しようとするとDLLのエラーになってCygwinプロンプトが止まってしまいます。
そこで下記の手順を実行

ash.exeを実行

コマンドプロンプト(Windowsのヤツ)を開いて下記の通りに実行。
※私はD:\cygwinにインストールしています。
※binディレクトリまでカレントを移動してください。

D:\cygwin\bin>ash.exe
$
rebaseallコマンドを実行

引き続き、rebaseallコマンドを起動したashで実行します。

D:\cygwin\bin>ash.exe
$ ./rebaseall

しばらく待って、下記のように$のプロンプトが表示されれば処理は終了しています。

D:\cygwin\bin>ash.exe
$ ./rebaseall
$
cygwin実行時にzshになるように設定

cygwinをインストールしたディレクトリにある「Cygwin.bat」を下記の通りに編集します。
こうすることで、Cygwinを起動するとbashではなくzshが起動します。
setしているCYGWIN=ttyですが、これを指定していないとemacsを導入したときにC-x C-cのキーが無効になってしまいます。

@echo off
set CYGWIN=tty
D:
chdir D:\cygwin\bin
zsh --login -i
.zshrcを作成

Cygwinをインストールしたディレクトリツリーの中に「home/admin」があるはずです。
私の場合はD:\Cygwinにインストールしたので「D:\cygwin\home\Admin\」になります。
ここに「.zshrc」を作成します。
私の内容はこんな感じ、Linuxで利用している.zshrcから不必要な物を取り除いて利用しました。

# users generic .zshrc file for zsh(1)

## Environment variable configuration
#
# LANG
#
export LANG=ja_JP.UTF-8


## Default shell configuration
#
# set prompt
#
autoload colors
colors
case ${UID} in
0)
    PROMPT="%B%{${fg[red]}%}%/#%{${reset_color}%}%b "
    PROMPT2="%B%{${fg[red]}%}%_#%{${reset_color}%}%b "
    SPROMPT="%B%{${fg[red]}%}%r is correct? [n,y,a,e]:%{${reset_color}%}%b "
    [ -n "${REMOTEHOST}${SSH_CONNECTION}" ] && 
        PROMPT="%{${fg[cyan]}%}$(echo ${HOST%%.*} | tr '[a-z]' '[A-Z]') ${PROMPT}"
    ;;
*)
    PROMPT="%B%{${fg[yellow]}%}$(echo ${HOST%%.*} | tr '[a-z]' '[A-Z]')%% "
    PROMPT2="%{${fg[red]}%}%_%%%{${reset_color}%} "
    RPROMPT="%B%{${fg[red]}%}%/%{${reset_color}%}%b "
    SPROMPT="%{${fg[red]}%}%r is correct? [n,y,a,e]:%{${reset_color}%} "
    [ -n "${REMOTEHOST}${SSH_CONNECTION}" ] && 
        PROMPT="%{${fg[cyan]}%}$(echo ${HOST%%.*} | tr '[a-z]' '[A-Z]') ${PROMPT}"
    ;;
esac

# auto change directory
#
setopt auto_cd

# auto directory pushd that you can get dirs list by cd -[tab]
#
setopt auto_pushd

# command correct edition before each completion attempt
#
setopt correct

# compacked complete list display
#
setopt list_packed

# no remove postfix slash of command line
#
setopt noautoremoveslash

# no beep sound when complete list displayed
#
setopt nolistbeep


## Keybind configuration
#
# emacs like keybind (e.x. Ctrl-a goes to head of a line and Ctrl-e goes 
#   to end of it)
#
bindkey -e

# historical backward/forward search with linehead string binded to ^P/^N
#
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
bindkey "\\ep" history-beginning-search-backward-end
bindkey "\\en" history-beginning-search-forward-end


## Command history configuration
#
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt hist_ignore_dups     # ignore duplication command history list
setopt share_history        # share command history data


## Completion configuration
#
fpath=(~/.zsh/functions/Completion ${fpath})
autoload -U compinit
compinit


## zsh editor
#
autoload zed


## Prediction configuration
#
#autoload predict-on
#predict-off


## Alias configuration
#
# expand aliases before completing
#
setopt complete_aliases     # aliased ls needs if file/dir completions work

alias where="command -v"
alias j="jobs -l"

case "${OSTYPE}" in
freebsd*|darwin*)
    alias ls="ls -G -w"
    ;;
linux*)
    alias ls="ls --color"
    ;;
esac

alias la="ls -a"
alias lf="ls -F"
alias ll="ls -l"

alias du="du -h"
alias df="df -h"

alias su="su -l"

case "${OSTYPE}" in
darwin*)
    alias updateports="sudo port selfupdate; sudo port outdated"
    alias portupgrade="sudo port upgrade installed"
    ;;
freebsd*)
    case ${UID} in
    0)
        updateports() 
        {
            if [ -f /usr/ports/.portsnap.INDEX ]
            then
                portsnap fetch update
            else
                portsnap fetch extract update
            fi
            (cd /usr/ports/; make index)

            portversion -v -l \<
        }
        alias appsupgrade='pkgdb -F && BATCH=YES NO_CHECKSUM=YES portupgrade -a'
        ;;
    esac
    ;;
esac


## terminal configuration
#
unset LSCOLORS
case "${TERM}" in
xterm)
    export TERM=xterm-color
    ;;
kterm)
    export TERM=kterm-color
    # set BackSpace control character
    stty erase
    ;;
cons25)
    unset LANG
    export LSCOLORS=ExFxCxdxBxegedabagacad
    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'
    zstyle ':completion:*' list-colors \
        'di=;34;1' 'ln=;35;1' 'so=;32;1' 'ex=31;1' 'bd=46;34' 'cd=43;34'
    ;;
esac

# set terminal title including current directory
#
case "${TERM}" in
kterm*|xterm*)
    precmd() {
        echo -ne "\033]0;${USER}@${HOST%%.*}:${PWD}\007"
    }
    export LSCOLORS=exfxcxdxbxegedabagacad
    export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
    zstyle ':completion:*' list-colors \
        'di=34' 'ln=35' 'so=32' 'ex=31' 'bd=46;34' 'cd=43;34'
    ;;
esac

#set pash of local bin
export PATH=$PATH:/home/kamuycikap/bin

## load user .zshrc configuration file
#
[ -f ~/.zshrc.mine ] && source ~/.zshrc.mine
環境変数PATHにCygwinのbinフォルダを指定する

環境変数PATHの設定にCygwinをインストールしたディレクトリのbinディレクトリを追加しなければならない。
私の場合は環境変数PATHに、d:\cygwin\bin を設定しておく。
Cygwin シェルの中からwhich zsh をすると、/usr/bin/zsh が返ってくるのだけれど、これらは d:\cygwin\usr\bin の下にはなく、d:\cygwin\bin の下にある。
これをやっておかないと、Meadow等からzshをコールするときにうまくいかない。

いよいよzsh起動

デスクトップにできているであろう「Cygwin」をクリックすればzshが起動します。
これでWindows7でも快適にzshライフが送れます。


優良アダルトサイト紹介の最終形態!!MaxInfo