Skip to content

Instantly share code, notes, and snippets.

@kickbase
Created December 3, 2018 11:43
Show Gist options
  • Select an option

  • Save kickbase/72b318ab714a15202e9420ffbb418d30 to your computer and use it in GitHub Desktop.

Select an option

Save kickbase/72b318ab714a15202e9420ffbb418d30 to your computer and use it in GitHub Desktop.
[ zsh ] my .zshrc settings
# Homebrewのパッケージ
export PATH=/usr/local/bin:$PATH
# SSHで接続した先で日本語が使えるようにする
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# ページャ
export PAGER=/usr/local/bin/vimpager
export MANPAGER=/usr/local/bin/vimpager
# suffix alias
alias -s rb='ruby'
alias -s py='python'
# キーバインドを開放
# http://rcmdnk.github.io/blog/2013/06/01/computer-bash-linux-mac/
tty -s && stty stop undef # C-s
tty -s && stty start undef # C-q
if [[ "$OSTYPE" =~ "darwin" ]];then
tty -s && stty discard undef # C-o
fi
# rmはゴミ箱経由しないのでゴミ箱に送るrmtrashコマンドに差し替え
alias rm="rmtrash"
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# pyenv
export PYENV_ROOT="${HOME}/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
fi
# ターミナル上のpythonで補完が効くようにする
# http://www.sakito.com/2008/10/terminalpython.html
export PYTHONSTARTUP=${HOME}/.pystartup
# Blender
alias blender='/Applications/Blender/blender.app/Contents/MacOS/blender'
alias bpip='/Applications/Blender/blender.app/Contents/Resources/2.79/python/bin/pip'
# 補完候補を詰めて表示
setopt list_packed
# 補完候補表示時などでビープ音をならないように設定
setopt nolistbeep
# brewのzsh-completionsを使ってzshの補完を強化
# http://qiita.com/maru_cc/items/4dfaa99be7bf95cf68bb
if [ -e /usr/local/share/zsh-completions ]; then
fpath=(/usr/local/share/zsh-completions $fpath)
fi
# http://wada811.blogspot.com/2014/09/zsh-cdr.html
# cdr, add-zsh-hook を有効化
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
# cdr の設定
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-max 500
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-file "$HOME/.cache/shell/chpwd-recent-dirs"
zstyle ':chpwd:*' recent-dirs-pushd true
# peco
# http://shibayu36.hatenablog.com/entry/2014/06/27/223538
for f (~/.zsh/peco-sources/*) source "${f}" # load peco sources
bindkey '^r' peco-select-history
bindkey '^j' peco-find-file # C-jを割り当て。押しやすいので
bindkey '\ex' peco-M-x
alias -g H='$(git-hash)'
alias -g F='$(git-changed-files)'
alias -g B='`git branch | peco | sed -e "s/^\*[ ]*//g"`'
alias -g s="peco-mdfind"
# zsh-bd
# http://blog.glidenote.com/blog/2014/05/15/zsh-bd/
# 上位のディレクトリに直接移動
source ~/.zsh/bd/bd.zsh
# コマンドを実行するたびに英数モードに切り替える
# http://hotolab.net/blog/zsh_force_alphanumeric/
autoload -Uz add-zsh-hook
function force-alphanumeric {
case "${OSTYPE}" in
darwin*)
(osascript -e 'tell application "System Events" to key code {102}' &)
esac
}
add-zsh-hook precmd force-alphanumeric
# 日本語ファイル名を表示可能にする
setopt print_eight_bit
# 高機能なワイルドカード展開を使用する
setopt extended_glob
# グロッピングを解除
# http://d.hatena.ne.jp/eitya/20110707/1310023383
setopt nonomatch
# cd-bookmark
# ニックネーム付きでブックマークを管理。peco対応済み。
# ~/.cdboookmarkに設定が保存される
# http://qiita.com/mollifier/items/46b080f9a5ca9f29674e
# http://tuki0918.hatenablog.com/entry/2014/07/03/220101
fpath=($HOME/.zsh/cd-bookmark(N-/) $fpath)
autoload -Uz cd-bookmark
alias b='cd-bookmark'
function peco_open_bookmark() {
cd $(cd-bookmark | peco | awk -F"|" '{ print $2 }' | xargs)
zle reset-prompt
ls -a
}
zle -N peco_open_bookmark
bindkey '^s' peco_open_bookmark
# z
# https://github.com/knu/z/blob/master/z.sh
. `brew --prefix`/etc/profile.d/z.sh
compctl -U -K _z_zsh_tab_completion ${_Z_CMD:-z}
alias j="z"
# シェルを再ログイン(再起動)して読み込む
alias relogin='exec $SHELL -l'
## 補完機能の強化
# http://qiita.com/ToruIwashita/items/5cfa382e9ae2bd0502be
autoload -Uz compinit && compinit -u
zstyle ':completion:*' menu select interactive
setopt menu_complete
zmodload zsh/complist # "bindkey -M menuselect"設定できるようにするためのモジュールロード
bindkey -v '^i' expand-or-complete # 補完開始
bindkey -M menuselect '^g' .send-break # send-break2回分の効果
bindkey -M menuselect '^i' forward-char # 補完候補1つ右へ
bindkey -M menuselect '^j' .accept-line # accept-line2回分の効果
bindkey -M menuselect '^k' accept-and-infer-next-history # 次の補完メニューを表示する
bindkey -M menuselect '^n' down-line-or-history # 補完候補1つ下へ
bindkey -M menuselect '^p' up-line-or-history # 補完候補1つ上へ
bindkey -M menuselect '^r' history-incremental-search-forward # 補完候補内インクリメンタルサーチ
## case-insensitive (all),partial-word and then substring completion
## 大文字と小文字を区別しない
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' \
'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
## 入力しているコマンド名が間違っている場合にもしかして:を出す。
setopt correct
# ビープを鳴らさない
setopt nobeep
## PROMPT変数内で変数参照する
setopt prompt_subst
## ^Dでログアウトしない。
setopt ignoreeof
## バックグラウンドジョブが終了したらすぐに知らせる。
setopt no_tify
# 補完
## タブによるファイルの順番切り替えをしない
unsetopt auto_menu
# cd -[tab]で過去のディレクトリにひとっ飛びできるようにする
setopt auto_pushd
# ディレクトリ名を入力するだけでcdできるようにする
setopt auto_cd
alias ...='cd ../..'
alias ....='cd ../../..'
# Emacs
alias emacs="/Applications/Emacs.app/Contents/MacOS/Emacs -nw"
alias E="/Applications/Emacs.app/Contents/MacOS/Emacs -nw --daemon"
alias e="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -nw -a ''"
alias ekill="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e '(kill-emacs)'"
# zshのカレントディレクトリをEmacsのDiredで開く
# http://masutaka.net/chalow/2011-09-28-1.html
function dired () {
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e "(dired \"${1:a}\")"
}
# EmacsのDiredを元にzshのカレントディレクトリを変更
# http://masutaka.net/chalow/2011-09-28-1.html
function cde () {
EMACS_CWD=`/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e "
(expand-file-name
(with-current-buffer
(if (featurep 'elscreen)
(let* ((frame-confs (elscreen-get-frame-confs (selected-frame)))
(num (nth 1 (assoc 'screen-history frame-confs)))
(cur-window-conf (cadr (assoc num (assoc 'screen-property frame-confs))))
(marker (nth 2 cur-window-conf)))
(marker-buffer marker))
(nth 1
(assoc 'buffer-list
(nth 1 (nth 1 (current-frame-configuration))))))
default-directory))" | sed 's/^"\(.*\)"$/\1/'`
echo "chdir to $EMACS_CWD"
cd "$EMACS_CWD"
}
# 重複する要素を自動的に削除
typeset -U path cdpath fpath manpath
path=(
$HOME/bin(N-/)
/usr/local/bin(N-/)
/usr/local/sbin(N-/)
$path
)
autoload -U promptinit; promptinit
autoload -Uz colors; colors
autoload -Uz vcs_info
autoload -Uz is-at-least
# begin VCS
zstyle ":vcs_info:*" enable git svn hg bzr
zstyle ":vcs_info:*" formats "(%s)-[%b]"
zstyle ":vcs_info:*" actionformats "(%s)-[%b|%a]"
zstyle ":vcs_info:(svn|bzr):*" branchformat "%b:r%r"
zstyle ":vcs_info:bzr:*" use-simple true
zstyle ":vcs_info:*" max-exports 6
if is-at-least 4.3.10; then
zstyle ":vcs_info:git:*" check-for-changes true # commitしていないのをチェック
zstyle ":vcs_info:git:*" stagedstr "<S>"
zstyle ":vcs_info:git:*" unstagedstr "<U>"
zstyle ":vcs_info:git:*" formats "(%b) %c%u"
zstyle ":vcs_info:git:*" actionformats "(%s)-[%b|%a] %c%u"
fi
function vcs_prompt_info() {
LANG=en_US.UTF-8 vcs_info
[[ -n "$vcs_info_msg_0_" ]] && echo -n " %{$fg[yellow]%}$vcs_info_msg_0_%f"
}
# end VCS
OK="^_^ "
NG="X_X "
PROMPT=""
PROMPT+="%(?.%F{green}$OK%f.%F{red}$NG%f) "
PROMPT+="%F{blue}%~%f"
PROMPT+="\$(vcs_prompt_info)"
PROMPT+="
"
PROMPT+="%% "
RPROMPT="[%*]"
alias -s as='vim'
# -n 行数表示, -I バイナリファイル無視, svn関係のファイルを無視
alias grep="grep --color -n -I --exclude='*.svn-*' --exclude='entries' --exclude='*/cache/*'"
# ls
alias ls="ls -G"
alias l="ls -la"
alias la="ls -a"
alias l1="ls -1"
# tree N: 文字化け対策, C:色をつける
alias tree="tree -NC"
alias -g o="open"
bindkey -e
function cdup() {
echo
cd ..
zle reset-prompt
}
zle -N cdup
bindkey '^x^j' cdup
#ヒストリーサイズ設定
# http://qiita.com/kotashiratsuka/items/ae37757aa1d31d1d4f4d
HISTFILE=$HOME/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000
PATH=${PATH}:~/bin
#ヒストリの一覧を読みやすい形に変更
HISTTIMEFORMAT="[%Y/%M/%D %H:%M:%S] "
setopt APPEND_HISTORY # ヒストリファイルを上書きするのではなく、追加するようにする
setopt EXTENDED_HISTORY # ヒストリに時刻情報もつける
setopt HIST_EXPIRE_DUPS_FIRST # 履歴がいっぱいの時は最も古いものを先ず削除
setopt HIST_FIND_NO_DUPS # 履歴検索中、重複を飛ばす
setopt HIST_NO_FUNCTIONS # ヒストリリストから関数定義を除く
setopt HIST_IGNORE_DUPS # 前のコマンドと同じならヒストリに入れない
setopt HIST_IGNORE_ALL_DUPS # 重複するヒストリを持たない
setopt HIST_NO_STORE # history コマンドをヒストリに入れない
setopt HIST_REDUCE_BLANKS # 履歴から冗長な空白を除く
setopt SHARE_HISTORY # 履歴を共有
setopt hist_ignore_dups # 直前と同じコマンドをヒストリに追加しない
setopt hist_reduce_blanks # ヒストリに保存するときに余分なスペースを削除する
# HISTIGNORE
# http://mollifier.hatenablog.com/entry/20090728/p1
zshaddhistory() {
local line=${1%%$'\n'}
local cmd=${line%% *}
# 以下の条件をすべて満たすものだけをヒストリに追加する
[[ ${#line} -ge 4
&& ${cmd} != (l|l[sal])
&& ${cmd} != (c|cd)
&& ${cmd} != (m|man)
&& ${cmd} != (rm)
&& ${cmd} != (uninstall)
&& ${cmd} != (j)
&& ${cmd} != (b)
]]
}
# タイトルバーに[一個上のディレクトリ] / [現在のディレクトリ]を表示 (cd時にも発動)
precmd() {
local str="\033]0;$(pwd | rev | awk -F \/ '{print "/"$1"/"$2}'| rev)\007"
eval 'ls -a;echo -ne ${str}'
}
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment