-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_git
27 lines (24 loc) · 897 Bytes
/
.bash_git
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
#!/bin/bash
fzf_git_list() {
local selections=$(
git ls-files | \
fzf --ansi \
--preview 'if ( command -v bat >/dev/null); then
bat --color=always --theme="Solarized (dark)" --style=numbers --line-range :500 {1}
else
cat {1}
fi'
)
if [[ -n $selections ]]; then
local selected="$selections"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
fi
}
# Required to refresh the prompt after fzf
bind -m emacs-standard '"\er": redraw-current-line'
bind -m emacs-standard '"\e^": history-expand-line'
# ctrl-o - Paste the selected file path into the command line
if [ $BASH_VERSINFO -gt 3 ]; then
bind -m emacs-standard -x '"\C-o": "fzf_git_list"'
fi