-
Notifications
You must be signed in to change notification settings - Fork 0
/
.fzf.bash
47 lines (37 loc) · 1.25 KB
/
.fzf.bash
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
# Setup fzf
# ---------
if [[ ! "$PATH" == */home/abdullah/.fzf/bin* ]]; then
export PATH="${PATH:+${PATH}:}/home/abdullah/.fzf/bin"
fi
# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/home/abdullah/.fzf/shell/completion.bash" 2> /dev/null
# Key bindings
# ------------
source "/home/abdullah/.fzf/shell/key-bindings.bash"
# external functions
fzf-git-branch() {
git rev-parse HEAD > /dev/null 2>&1 || return
git branch --color=always --all --sort=-committerdate |
grep -v HEAD |
fzf --height 50% --ansi --no-multi --preview-window right:65% \
--preview 'git log -n 50 --color=always --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed "s/.* //" <<< {})' |
sed "s/.* //"
}
fzf-git-checkout() {
git rev-parse HEAD > /dev/null 2>&1 || return
local branch
branch=$(fzf-git-branch)
if [[ "$branch" = "" ]]; then
echo "No branch selected."
return
fi
# If branch name starts with 'remotes/' then it is a remote branch. By
# using --track and a remote branch name, it is the same as:
# git checkout -b branchName --track origin/branchName
if [[ "$branch" = 'remotes/'* ]]; then
git checkout --track $branch
else
git checkout $branch;
fi
}