Skip to content

Instantly share code, notes, and snippets.

@myokoym
Last active February 23, 2018 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myokoym/c7fc9f56805f64fb48ad9b297d7e17bf to your computer and use it in GitHub Desktop.
Save myokoym/c7fc9f56805f64fb48ad9b297d7e17bf to your computer and use it in GitHub Desktop.
Zsh×pecoの設定(history、ghq、cdr) feat. [.zshrcを晒す - Qiita](https://qiita.com/reireias/items/60ee9934fb1f5d94f125#peco)
# cdr
if [[ -n $(echo ${^fpath}/chpwd_recent_dirs(N)) && -n $(echo ${^fpath}/cdr(N)) ]]; then
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-max 1000
zstyle ':chpwd:*' recent-dirs-file "$HOME/.cache/chpwd-recent-dirs"
fi
# }}}
# PECO {{{
# peco
function peco-history-selection() {
BUFFER=`history -n 1 | tac | awk '!a[$0]++' | peco`
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N peco-history-selection
bindkey '^R' peco-history-selection
function peco-ghq-look () {
local ghq_roots="$(git config --path --get-all ghq.root)"
local selected_dir=$(ghq list --full-path | \
xargs -I{} ls -dl --time-style=+%s {}/.git | sed 's/.*\([0-9]\{10\}\)/\1/' | sort -nr | \
sed "s,.*\(${ghq_roots/$'\n'/\|}\)/,," | \
sed 's/\/.git//' | \
peco --prompt="cd-ghq >" --query "$LBUFFER")
if [ -n "$selected_dir" ]; then
BUFFER="cd $(ghq list --full-path | grep --color=never -E "/$selected_dir$")"
zle accept-line
fi
}
zle -N peco-ghq-look
bindkey '^G' peco-ghq-look
function peco-cdr () {
local selected_dir="$(cdr -l | sed 's/^[0-9]\+ \+//' | peco --prompt="cdr >" --query "$LBUFFER")"
if [ -n "$selected_dir" ]; then
BUFFER="cd ${selected_dir}"
zle accept-line
fi
}
zle -N peco-cdr
bindkey '^E' peco-cdr
# }}}
#!/bin/zsh
set -e
#set -x
if ! which go; then
sudo apt-get install golang
fi
if [ -z $GOPATH ]; then
cat <<'EOT' >> ~/.zshrc
export GOPATH=$HOME/.go
export PATH=$GOPATH/bin:$PATH
EOT
. ~/.zshrc
fi
if ! which ghq; then
echo "Installing..."
go get -u github.com/motemen/ghq
fi
if ! which peco; then
echo "Installing..."
go get -u github.com/peco/peco/cmd/peco/
fi
if ! grep "peco-cdr" ~/.zshrc; then
wget https://gist.githubusercontent.com/myokoym/c7fc9f56805f64fb48ad9b297d7e17bf/raw/part-of-zshrc
cat part-of-zshrc >> ~/.zshrc
fi
if ! git config ghq.root; then
cat <<EOT >> ~/.gitconfig
[ghq]
root = ~/.ghq
root = $GOPATH/src
EOT
fi
@myokoym
Copy link
Author

myokoym commented Feb 22, 2018

curl -fsSL https://gist.githubusercontent.com/myokoym/c7fc9f56805f64fb48ad9b297d7e17bf/raw/setup.zsh | zsh && . ~/.zshrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment