]> gitweb @ CieloNegro.org - sugar.git/blob - dot-files/_zshrc
d5fdcf850a7e95ae29ad3f515e6487a6559e4372
[sugar.git] / dot-files / _zshrc
1 #!/bin/zsh
2 bindkey -e
3
4 stty -ixon ixany
5 stty erase '^H'
6
7 zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z} r:|[/]=* r:|=*'
8 zstyle ':completion:*' use-cache true
9
10 if [ -d "$HOME/.zfunc" ]; then
11     fpath=($HOME/.zfunc $fpath)
12     autoload -U ~/.zfunc/*(:t)
13     function r() {
14         local f
15         f=(~/.zfunc/*(.))
16         unfunction $f:t 2> /dev/null
17         autoload -U $f:t
18     }
19 fi
20
21 if [ -f "$HOME/.ssh/known_hosts" ]; then
22     _cache_hosts=(`perl -ne  'if (/^([a-zA-Z0-9.-]+)/) { print "$1\n";}' ~/.ssh/known_hosts`)
23 fi
24
25 autoload -U colors
26 colors
27
28 setopt no_beep
29 setopt auto_cd
30 setopt auto_list
31 setopt auto_menu
32 setopt auto_name_dirs
33 setopt auto_param_keys
34 setopt auto_param_slash
35 setopt auto_remove_slash
36 setopt c_bases
37 setopt chase_links
38 setopt complete_aliases
39 setopt correct
40 setopt equals
41 setopt glob_complete
42 setopt prompt_bang
43 setopt prompt_percent
44 setopt prompt_subst
45 setopt pushd_ignore_dups
46 setopt pushd_to_home
47 setopt sh_file_expansion
48 setopt always_last_prompt
49 setopt extended_glob
50 setopt hist_ignore_all_dups
51 setopt hist_ignore_space
52 setopt inc_append_history
53 setopt share_history
54
55 function _we_are_in_gnu_screen () {
56     [ "$WINDOW" != "" ]
57 }
58
59 _prompt_base='%B[%n@%m] %{%(?.$fg[green].$fg[red])%}%#%{$reset_color%}%b '
60 if ( _we_are_in_gnu_screen ); then
61     # GNU Screen has a capability to set its window title by "ESC k
62     # {string} ESC \". We want to reset the title to `_' to show we
63     # aren't running any command now.
64     PROMPT=$'%{\ek_\e\\%}'$_prompt_base
65 else
66     PROMPT=$_prompt_base
67 fi
68
69 function preexec() { # Hook
70     if { _we_are_in_gnu_screen } then
71         # Set the window title of GNU Screen.
72         local cmd=${1[(wr)^(*=*|sudo|nice|env|time|-*|[0-9]*)]}
73         printf "\ek$cmd\e\\"
74     fi
75 }
76
77 function chpwd() { # Hook
78     local dirinfo=$(print_directory_info)
79
80     case $dirinfo in
81         "")
82             RPROMPT='%U%~%u';;
83         *)
84             RPROMPT="%U%~%u %U($dirinfo)%u";;
85     esac
86 }
87
88 function print_directory_info() {
89     local vcs_type=$(print_vcs_type $(pwd))
90
91     case $vcs_type in
92         git)
93             git branch --no-color 2>/dev/null \
94                 | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/';;
95         hg)
96             hg branch 2>/dev/null;;
97         darcs-*)
98             # Delete `darcs-' at the beginning.
99             echo ${vcs_type#darcs-};;
100         *)
101             # Unknown
102             echo
103     esac
104 }
105
106 function print_vcs_type() {
107     local absdir=$1
108
109     if [[ -d $absdir/.git ]] then
110         echo git
111     elif [[ -d $absdir/.hg ]] then
112         echo hg
113     elif [[ -d $absdir/_darcs ]] then
114         echo darcs-$(basename $absdir)
115     else
116         # Nothing.
117         if [[ $absdir = "/" ]] then
118             # This is the root directory so exit from the recursion.
119             echo
120         else
121             # Recurse to the parent dir.
122             print_vcs_type $(dirname $absdir)
123         fi
124     fi
125 }
126 chpwd
127
128 HISTFILE="$HOME/.zhistory"
129 HISTSIZE=6000000
130 SAVEHIST=6000000
131
132 alias -g L="| $PAGER"
133 alias -g G="| grep"
134 alias -g H="| head"
135 alias -g T="| tail"
136
137 alias ..='cd ..'
138 alias cd..='cd ..'
139 alias p='pushd'
140 alias o='popd'
141 alias d='dirs'
142 alias df='df -h'
143 alias ed='ed -p "ed> "'
144 alias du='du -k'
145 alias nc='nc -vv'
146 alias mwget="wget --user-agent='Mozilla/1.4b'"
147 alias pstow="pushd /usr/local/stow"
148 alias w3m="w3m -O UTF-8"
149 alias w3mb="w3m -O UTF-8 -B"
150 alias pkgsrc="pushd /usr/pkgsrc"
151
152 alias aria="ssh -X admin@aria.cielonegro.org"
153 alias nem="ssh -X pho@nem.cielonegro.org"
154 alias mikasa="ssh -X daimon@mikasa.tomilab.net"
155
156 alias aria-emacs="ssh -f -X admin@aria.cielonegro.org emacs"
157
158 alias g1="ssh pho@g1.cuenote.jp"
159 alias g2="ssh pho@g2.cuenote.jp"
160 alias mana="ssh pho@mana"
161
162 if [ $(hostname) = "aria.cielonegro.org" ]; then
163     alias safari="open -a Safari"
164     alias unstuff='open -a StuffIt\ Expander.app'
165     alias pa='open -a NiseRingo.app'
166     alias heboris='open /Applications/HeborisUEMac/exe/Heboris\ OpenGL.app'
167     alias hengband='open ~/Applications/hengband*/Hengband*'
168 fi
169
170 if [ $(uname) = "Darwin" ]; then
171     alias ldd="otool -L"
172
173     alias ls='ls -Fw'
174     alias la='ls -aw'
175     alias l='ls -lw'
176     alias lls='ls -law'
177
178     alias top='/usr/bin/top -X -o cpu'
179 else
180     alias ls='ls -F'
181     alias la='ls -a'
182     alias l='ls -l'
183     alias lls='ls -la'
184 fi
185
186 # The following lines were added by compinstall
187
188 zstyle :compinstall filename "$HOME/.zshrc"
189
190 autoload -U compinit
191 compinit
192 # End of lines added by compinstall
193
194 if [ "x$WINDOW" = "x" ]; then
195     if which fortune 2>&1 >/dev/null; then
196         fortune
197     fi
198 fi
199
200 if [ -e ".motd" ]; then
201     cat .motd
202 fi
203
204 if which ssh-agent-manager 2>&1 >/dev/null; then
205     eval `ssh-agent-manager -s`
206 fi