forked from linhmtran168/mac_dotfiles
/
peco.zsh
66 lines (58 loc) · 1.35 KB
/
peco.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
##
# Peco
##
# Peco for repo
function peco-src () {
local selected_dir=$(ghq list --full-path | peco --query "$LBUFFER")
if [ -n "$selected_dir" ]; then
BUFFER="cd ${selected_dir}"
zle accept-line
fi
zle clear-screen
}
zle -N peco-src
bindkey '^]' peco-src
# peco for history
function peco-select-history() {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
BUFFER=$(\history -n 1 | \
eval $tac | \
peco --query "$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history
# peco for git
function git-hash() {
# git log --oneline --branches --decorate=full | peco | awk '{print $1}'
git lg | peco | sed -e "s/^[\*\|][ |\\\/\* ]*//g" | awk '{print $1}'
}
alias -g GH='$(git-hash)'
function git-branch() {
git branch -a | peco | sed -e "s/^\*\s*//g"
}
alias -g GB='$(git-branch)'
function git-reflog() {
git reflog | peco | awk '{print $1}'
}
alias -g GR='$(git-reflog)'
function git-changed-files() {
git status --short | peco | awk '{print $2}'
}
alias -g GF='$(git-changed-files)'
# PS
function peco-ps() {
ps aux | peco | awk '{print $2}'
}
alias -g PID='$(peco-ps)'
# File
function peco-file-search() {
find . -type f -name "*${1}*" | grep -v "/\.git\|/\.svn\|/\.hg" | peco
}
alias -g FN='$(peco-file-search)'