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)
23 unfunction $f:t 2> /dev/null
28 if [[ -f "$HOME/.ssh/known_hosts" ]]; then
29 _cache_hosts=(`perl -ne 'if (/^([a-zA-Z0-9.-]+)/) { print "$1\n";}' ~/.ssh/known_hosts`)
40 setopt auto_param_keys
41 setopt auto_param_slash
42 setopt auto_remove_slash
45 setopt complete_aliases
52 setopt pushd_ignore_dups
54 setopt sh_file_expansion
55 setopt always_last_prompt
57 setopt hist_ignore_all_dups
58 setopt hist_ignore_space
59 setopt inc_append_history
62 function _we_are_in_gnu_screen () {
66 function _we_are_in_ssh_session () {
67 [[ -n "$SSH_CONNECTION" ]]
70 function _we_are_in_emacs () {
71 [[ -n "$INSIDE_EMACS" ]]
74 _prompt_base='%B[%n@%m] %{%(?.$fg[green].$fg[red])%}%#%{$reset_color%}%b '
75 if ( _we_are_in_gnu_screen ); then
76 # GNU Screen has a capability to set its window title by "ESC k
77 # {string} ESC \". We want to reset the title to `_' to show we
78 # aren't running any command now.
79 PROMPT=$'%{\ek_\e\\%}'$_prompt_base
84 autoload -U add-zsh-hook
86 function _gnu_screen_preexec() {
87 if { _we_are_in_gnu_screen } then
88 # Set the window title of GNU Screen.
89 local cmd=${1[(wr)^(*=*|sudo|nice|env|time|ssh|-*|[0-9]*)]}
93 add-zsh-hook preexec _gnu_screen_preexec
95 function _dirinfo_precmd() {
96 local dirinfo="$(print_directory_info $(pwd))"
102 RPROMPT="%U%~%u %U($dirinfo)%u";;
105 add-zsh-hook precmd _dirinfo_precmd
107 function print_directory_info() {
110 if [[ -r $absdir/.git ]] then
112 git branch --no-color 2>/dev/null \
113 | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
115 elif [[ -r $absdir/.hg/branch ]] then
117 local hgbranch=`cat $absdir/.hg/branch`
118 if [[ -e $absdir/.hg/unpushed ]] then
124 elif [[ -d $absdir/_darcs ]] then
128 elif [[ -r $absdir/CVS/Repository ]] then
130 cat $absdir/CVS/Repository \
131 | sed -e 's!\([^/]*\).*!\1!'
135 if [[ $absdir = "/" ]] then
136 # This is the root directory so exit from the recursion.
139 # Recurse to the parent dir.
140 print_directory_info $(dirname $absdir)
146 fgrep --with-filename --line-number --context=1 --colour=always "$@" | $PAGER
152 if [[ $# -gt 0 ]]; then
153 percol_opts=("--query" "$1")
156 ps aux | percol "${percol_opts[@]}" | awk '{ print $2 }'
162 if [[ $1 =~ "^[^-]" ]]; then
167 ppgrep "${ppgrep_opts[@]}" | xargs kill "$@"
170 function find_tac_command() {
171 if which gtac >&/dev/null; then
173 elif which tac >&/dev/null; then
180 function percol_select_history() {
182 tac_cmd=($(find_tac_command))
185 selected=$("${tac_cmd[@]}" "$HISTFILE" | \
186 sed 's/^: [0-9]*:[0-9]*;//' | \
187 awk 'seen[$0] {next} {seen[$0]++; print}' | \
188 percol --match-method regex --query "$LBUFFER")
190 if [[ $? -eq 0 ]]; then
192 CURSOR="$#BUFFER" # move cursor to the end of line
194 #zle accept-line # uncomment this to execute the selected one immediately.
199 if which percol >&/dev/null; then
200 zle -N percol_select_history
201 bindkey '^R' percol_select_history
204 HISTFILE="$HOME/.zhistory"
208 # Select directories with z(1)
209 if [[ -r "$HOME/sandbox/_misc/z/z.sh" ]]; then
210 source "$HOME/sandbox/_misc/z/z.sh"
212 function percol_select_directory() {
214 tac_cmd=($(find_tac_command))
217 selected=$(_z -r 2>&1 | \
219 percol --query "$LBUFFER" | \
220 sed -r 's/[^[:space:]]+[[:space:]]+//')
222 if [[ $? -eq 0 ]]; then
224 selected="" # Without this, zsh treats this variable as a
225 # candidate for a "named directory".
232 if which percol >&/dev/null; then
233 zle -N percol_select_directory
234 bindkey '\C-xd' percol_select_directory
241 if whence -p lv >/dev/null; then
243 elif which less >&/dev/null; then
245 elif which more >&/dev/null; then
248 echo >&2 "$0: no pager commands are found"
252 command "${lv_cmd[@]}" "$@"
255 alias -g L="| $PAGER"
259 alias -g X="| hexdump -C"
268 alias ed='ed -p "ed> "'
269 alias man="LANG=C man"
270 alias mwget="wget --user-agent='Mozilla/1.4b'"
272 alias pkgsrc="pushd /usr/pkgsrc"
273 alias pstow="pushd /usr/local/stow"
274 alias w3m="w3m -O UTF-8"
275 alias w3mb="w3m -O UTF-8 -B"
277 alias aria-emacs="ssh -f -X admin@aria.cielonegro.org emacsclient -c"
278 alias pho-dev-boinc="ssh -f -X pho@pho.dev.office.ymir.co.jp env LANG=C /home/pho/var/BOINC/run_manager"
280 if [[ $(hostname) = "aria.cielonegro.org" ]]; then
281 alias unstuff='open -a StuffIt\ Expander.app'
282 alias pa='open -a NiseRingo.app'
283 alias heboris='open /Applications/HeborisUEMac/exe/Heboris\ OpenGL.app'
284 alias hengband='open ~/Applications/hengband*/Hengband*'
286 elif [[ $(hostname) = "yukari.cielonegro.org" ]]; then
290 args=(${args[@]} $(printf %q "$arg"))
292 ssh kurumi open -a Safari ${args[@]}
294 function mfirefox () {
297 args=(${args[@]} $(printf %q "$arg"))
299 ssh kurumi open -a Firefox ${args[@]}
303 if [[ $(uname) = "Darwin" ]]; then
304 alias safari="open -a Safari"
313 #alias top='/usr/bin/top -X -o cpu'
314 alias top='/usr/bin/top -o cpu'
324 "Darwin" | "FreeBSD" | "NetBSD")
327 if [[ -f "/etc/redhat-release" ]]; then
328 cat "/etc/redhat-release"
329 elif [[ -f "/etc/SuSE-release" ]]; then
330 cat "/etc/SuSE-release"
332 echo -n "$0: I know this is "$(uname -o)" but " >&2
333 echo "have no idea about its distribution." >&2
337 echo "$0: Failed to detect the OS name." >&2
342 if _we_are_in_gnu_screen; then
343 # When we are in a GNU Screen session...
345 if _we_are_in_ssh_session; then
346 # Propagate remote session's bells to the local one.
350 if _we_are_in_emacs; then
351 # Without this, Emacs' term mode has trouble with backspaces.
355 # Run "fortune" if we aren't in a GNU Screen session.
356 if which fortune >/dev/null 2>&1; then
361 if which ssh-agent-manager >/dev/null 2>&1; then
362 eval `ssh-agent-manager -s`