7 # The following lines were added by compinstall
8 zstyle :compinstall filename "$HOME/.zshrc"
12 # End of lines added by compinstall
14 zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z} r:|[/]=* r:|=*'
15 zstyle ':completion:*' use-cache true
17 if [[ -d "$HOME/.zfunc" ]]; then
18 fpath=($HOME/.zfunc $fpath)
19 autoload -U ~/.zfunc/*(:t)
24 unfunction $f:t 2> /dev/null
29 if [[ -f "$HOME/.ssh/known_hosts" ]]; then
30 _cache_hosts=(`perl -ne 'if (/^([a-zA-Z0-9.-]+)/) { print "$1\n";}' ~/.ssh/known_hosts`)
41 setopt auto_param_keys
42 setopt auto_param_slash
43 setopt auto_remove_slash
46 setopt complete_aliases
53 setopt pushd_ignore_dups
55 setopt sh_file_expansion
56 setopt always_last_prompt
58 setopt hist_ignore_all_dups
59 setopt hist_ignore_space
60 setopt inc_append_history
63 function _we_are_in_gnu_screen () {
67 function _we_are_in_ssh_session () {
68 [[ -n "$SSH_CONNECTION" ]]
71 function _we_are_in_emacs () {
72 [[ -n "$INSIDE_EMACS" ]]
75 _prompt_base='%B[%n@%m] %{%(?.$fg[green].$fg[red])%}%#%{$reset_color%}%b '
76 if ( _we_are_in_gnu_screen ); then
77 # GNU Screen has a capability to set its window title by "ESC k
78 # {string} ESC \". We want to reset the title to `_' to show we
79 # aren't running any command now.
80 PROMPT=$'%{\ek_\e\\%}'$_prompt_base
85 autoload -U add-zsh-hook
87 function _gnu_screen_preexec() {
88 if { _we_are_in_gnu_screen } then
89 # Set the window title of GNU Screen.
90 local cmd=${1[(wr)^(*=*|sudo|nice|env|time|ssh|-*|[0-9]*)]}
94 add-zsh-hook preexec _gnu_screen_preexec
96 function _dirinfo_precmd() {
97 local dirinfo="$(print_directory_info $(pwd))"
103 RPROMPT="%U%~%u %U($dirinfo)%u";;
106 add-zsh-hook precmd _dirinfo_precmd
108 function print_directory_info() {
111 if [[ -r $absdir/.git ]] then
113 git branch --no-color 2>/dev/null \
114 | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
116 elif [[ -r $absdir/.hg/branch ]] then
118 local hgbranch=`cat $absdir/.hg/branch`
119 if [[ -e $absdir/.hg/unpushed ]] then
125 elif [[ -d $absdir/_darcs ]] then
129 elif [[ -r $absdir/CVS/Repository ]] then
131 cat $absdir/CVS/Repository \
132 | sed -e 's!\([^/]*\).*!\1!'
136 if [[ $absdir = "/" ]] then
137 # This is the root directory so exit from the recursion.
140 # Recurse to the parent dir.
141 print_directory_info $(dirname $absdir)
147 fgrep --with-filename --line-number --context=1 --colour=always "$@" | $PAGER
153 if [[ $# -gt 0 ]]; then
154 percol_opts=("--query" "$1")
157 ps aux | percol "${percol_opts[@]}" | awk '{ print $2 }'
163 if [[ $1 =~ "^[^-]" ]]; then
168 ppgrep "${ppgrep_opts[@]}" | xargs kill "$@"
171 function find_tac_command() {
172 if which gtac >&/dev/null; then
174 elif which tac >&/dev/null; then
181 function percol_select_history() {
183 tac_cmd=($(find_tac_command))
186 selected=$("${tac_cmd[@]}" "$HISTFILE" | \
187 sed 's/^: [0-9]*:[0-9]*;//' | \
188 awk 'seen[$0] {next} {seen[$0]++; print}' | \
189 percol --match-method regex --query "$LBUFFER")
191 if [[ $? -eq 0 ]]; then
193 CURSOR="$#BUFFER" # move cursor to the end of line
195 #zle accept-line # uncomment this to execute the selected one immediately.
200 if which percol >&/dev/null; then
201 zle -N percol_select_history
202 bindkey '^R' percol_select_history
205 HISTFILE="$HOME/.zhistory"
209 # Select directories with z(1)
210 if [[ -r "$HOME/sandbox/_misc/z/z.sh" ]]; then
211 source "$HOME/sandbox/_misc/z/z.sh"
213 function percol_select_directory() {
215 tac_cmd=($(find_tac_command))
218 selected=$(_z -r 2>&1 | \
220 percol --query "$LBUFFER" | \
221 sed -r 's/[^[:space:]]+[[:space:]]+//')
223 if [[ $? -eq 0 ]]; then
225 selected="" # Without this, zsh treats this variable as a
226 # candidate for a "named directory".
233 if which percol >&/dev/null; then
234 zle -N percol_select_directory
235 bindkey '\C-xd' percol_select_directory
242 if whence -p lv >/dev/null; then
244 elif which less >&/dev/null; then
246 elif which more >&/dev/null; then
249 echo >&2 "$0: no pager commands are found"
253 command "${lv_cmd[@]}" "$@"
256 alias -g L="| $PAGER"
260 alias -g X="| hexdump -C"
269 alias ed='ed -p "ed> "'
270 alias man="LANG=C man"
271 alias mwget="wget --user-agent='Mozilla/1.4b'"
273 alias pkgsrc="pushd /usr/pkgsrc"
274 alias pstow="pushd /usr/local/stow"
275 alias w3m="w3m -O UTF-8"
276 alias w3mb="w3m -O UTF-8 -B"
278 alias aria-emacs="ssh -f -X admin@aria.cielonegro.org emacsclient -c"
279 alias pho-dev-boinc="ssh -f -X pho@pho.dev.office.ymir.co.jp env LANG=C /home/pho/var/BOINC/run_manager"
281 if [[ $(hostname) = "aria.cielonegro.org" ]]; then
282 alias unstuff='open -a StuffIt\ Expander.app'
283 alias pa='open -a NiseRingo.app'
284 alias heboris='open /Applications/HeborisUEMac/exe/Heboris\ OpenGL.app'
285 alias hengband='open ~/Applications/hengband*/Hengband*'
287 elif [[ $(hostname) = "yukari.cielonegro.org" ]]; then
291 args=(${args[@]} $(printf %q "$arg"))
293 ssh kurumi open -a Safari ${args[@]}
295 function mfirefox () {
298 args=(${args[@]} $(printf %q "$arg"))
300 ssh kurumi open -a Firefox ${args[@]}
303 ssh kurumi open -a Dock
307 if [[ $(uname) = "Darwin" ]]; then
308 alias safari="open -a Safari"
317 #alias top='/usr/bin/top -X -o cpu'
318 alias top='/usr/bin/top -o cpu'
328 "Darwin" | "FreeBSD" | "NetBSD")
331 if [[ -f "/etc/redhat-release" ]]; then
332 cat "/etc/redhat-release"
333 elif [[ -f "/etc/SuSE-release" ]]; then
334 cat "/etc/SuSE-release"
336 echo -n "$0: I know this is "$(uname -o)" but " >&2
337 echo "have no idea about its distribution." >&2
341 echo "$0: Failed to detect the OS name." >&2
346 function _start_gpg_agent () {
347 if ! which gpg-agent >&/dev/null; then
348 # gpg-agent is not present.
352 if gpg-connect-agent /bye >&/dev/null; then
353 # gpg-agent is already running.
354 if [[ -f "${HOME}/.gpg-agent-info" ]]; then
355 . "${HOME}/.gpg-agent-info"
356 export GPG_AGENT_INFO
359 # gpg-agent is not running yet.
360 eval $(gpg-agent --daemon --write-env-file "${HOME}/.gpg-agent-info")
367 if _we_are_in_gnu_screen; then
368 # When we are in a GNU Screen session...
370 if _we_are_in_ssh_session; then
371 # Propagate remote session's bells to the local one.
375 if _we_are_in_emacs; then
376 # Without this, Emacs' term mode has trouble with backspaces.
380 # Run "fortune" if we aren't in a GNU Screen session.
381 if which fortune >/dev/null 2>&1; then
386 if which ssh-agent-manager >/dev/null 2>&1; then
387 eval `ssh-agent-manager -s`