-
Notifications
You must be signed in to change notification settings - Fork 4
/
fzf_functions.sh
executable file
·57 lines (46 loc) · 1.87 KB
/
fzf_functions.sh
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
#!/bin/env bash
# Keep fzf config and functions together
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
# I want tab to move up and down in the list, just like it does with my vim
# completion. With this config tab moves down, shift-tab moves up and
# ctrl-space toggles selection.
export FZF_DEFAULT_OPTS="--multi --pointer '>>' --bind 'ctrl-space:toggle,tab:down,shift-tab:up'"
f() {
fzf --bind='ctrl-/:toggle-preview' --preview "bat --style=numbers --color=always --line-range :500 {}" "$@"
}
# prove
_fzf_complete_prove() {
_fzf_complete --bind='ctrl-/:toggle-preview' --preview 'bat --style=numbers --color=always --line-range :50 {}' --reverse --multi --prompt="prove> " -- "$@" < <(
fd -e t
)
}
_fzf_complete_prove_post() {
awk '{print $1}'
}
[ -n "$BASH" ] && complete -F _fzf_complete_prove -o default -o bashdefault prove
# yath
_fzf_complete_yath() {
_fzf_complete --bind='ctrl-/:toggle-preview' --preview 'bat --style=numbers --color=always --line-range :50 {}' --reverse --multi --prompt="yath> " -- "$@" < <(
fd -e t
)
}
_fzf_complete_yath_post() {
awk '{print $1}'
}
[ -n "$BASH" ] && complete -F _fzf_complete_yath -o default -o bashdefault yath
cd_worktree() {
cd "$(git worktree list |
fzf --preview='git log --pretty=format:"%ad %<(8,trunc)%aL %h %s" --date=format:"%Y-%m-%d" -n10 {2} | tspin --words-blue oalders' \
--preview-window 'up,border-horizontal' |
awk '{print $1}')" || exit
}
rm_worktree() {
# Get list of worktrees and strip it down to the branch name
# [oalders/branch-name], which should generally also correspond to the tmux
# session name.
git worktree list |
fzf --preview='cd {1} && git status | tspin' \
--preview-window 'up,border-horizontal' |
sed -rn 's/.*\[(.*)\]/\1/gp' |
safe_xargs remove-worktree "$@"
}