-
Notifications
You must be signed in to change notification settings - Fork 4
/
kamp-files
executable file
·51 lines (45 loc) · 953 Bytes
/
kamp-files
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
#!/bin/sh
#
# pick files
#
# requires:
# - fd (https://github.com/sharkdp/fd)
# - fzf (https://github.com/junegunn/fzf)
# - bat (https://github.com/sharkdp/bat)
set -euf
usage() {
printf "Usage: %s: [-b <fd|rg|find|git>] -- [backend_options]\n" "$(basename "$0")" >&2
exit 2
}
backend="fd"
while getopts 'b:h' OPTION; do
case $OPTION in
b)
backend="$OPTARG"
;;
h|?)
usage
;;
esac
done
shift $((OPTIND - 1))
case "$backend" in
fd)
backend_cmd="fd --strip-cwd-prefix --type file $*"
;;
rg)
backend_cmd="rg --files $*"
;;
find)
backend_cmd="find . -type f $*"
;;
git)
backend_cmd="git ls-files $*"
;;
*)
usage
;;
esac
preview_cmd='bat --color=always --line-range=:500 {}'
eval "$backend_cmd" |
fzf --multi --prompt "${backend}> " --preview "$preview_cmd" --bind 'enter:become(kamp edit {+})'