-
Notifications
You must be signed in to change notification settings - Fork 0
/
fzfrc
67 lines (60 loc) · 1.58 KB
/
fzfrc
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
67
alias v="vim \$(fzf)"
alias vv="vim \$(git ls-files | fzf)"
alias vz="vim ~/.zshrc && source ~/.zshrc"
# fh - repeat history
fh() {
eval $(([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}
# fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-*} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# fkill - kill process
fkill() {
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]
then
kill -${1:-9} $pid
fi
}
# fbr - checkout git branch
fbr() {
local branches branch
branches=$(git branch) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | sed "s/.* //")
}
# fco - checkout git commit
fco() {
local commits commit
commits=$(git log --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf --tac +s +m -e) &&
git checkout $(echo "$commit" | sed "s/ .*//")
}
# fshow - git commit browser
fshow() {
local out sha q
while out=$(
git log --decorate=short --graph --oneline --color=always |
fzf --ansi --multi --no-sort --reverse --query="$q" --print-query); do
q=$(head -1 <<< "$out")
while read sha; do
[ -n "$sha" ] && git show --color=always $sha | less -R
done < <(sed '1d;s/^[^a-z0-9]*//;/^$/d' <<< "$out" | awk '{print $1}')
done
}
#unalias z
#z() {
#if [[ -z "$*" ]]; then
#cd "$(_z -l 2>&1 | fzf +s --tac | sed 's/^[0-9,.]* *//')"
#else
#_last_z_args="$@"
#_z "$@"
#fi
#}
#zz() {
#cd "$(_z -l 2>&1 | sed -n 's/^[0-9,.]* *//' | fzf -q $_last_z_args)"
#}