-
Notifications
You must be signed in to change notification settings - Fork 1
/
fzf-file
executable file
·46 lines (40 loc) · 1.23 KB
/
fzf-file
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
#!/bin/bash
# # debug
# set -o xtrace
declare SRCDIR
SRCDIR=$(dirname $(readlink -e $0))
if [[ $1 =~ -h|--help ]]; then
man -l $SRCDIR/help.1
exit
fi
# QUERY is optionally set externally: QUERY='foo bar' fzf-file
declare QUERY
if [[ ! -t 0 ]]; then # stdin not attached to a tty
unset FZF_DEFAULT_COMMAND
else
FZF_DEFAULT_COMMAND="rg --files $@" # support multiple directories
fi
declare VIEWER HEADER
if [[ -f $(which bat 2> /dev/null) ]]; then
HEADER='~4'
if [[ -n $QUERY ]]; then
VIEWER="bat --style=full --color=always --paging=always --pager 'less \"+/$QUERY\"'"
else
VIEWER="bat --style=full --color=always --paging=always"
fi
else
if [[ -n $QUERY ]]; then
VIEWER="less -NS '+/$QUERY'"
else
VIEWER="less -NS"
fi
fi
declare FZF_DEFAULT_OPTS="--ansi --header-first --exact --multi"
fzf --prompt='> ' \
--header "« F1: help, C-s: recursive search, RET: view, M-RET: open »" \
--bind "f1:execute(man -l $SRCDIR/help.1 || true)" \
--preview "$VIEWER {}" \
--preview-window "border-left:$HEADER" \
--bind "enter:execute($VIEWER {1})" \
--bind "alt-enter:execute($EDITOR {1})" \
--bind "ctrl-s:select-all+execute(uniq {+f} | QUERY='${QUERY}' fzf-search || true)+deselect-all"