-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz.fish
121 lines (106 loc) · 3.66 KB
/
fuzz.fish
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
begin
set prefix_rg 'rg --column --line-number --no-heading --color=always --smart-case'
set prefix_file 'fd --hidden --type f'
set prefix_dir 'fd --hidden --type d'
set preview_rg 'bat --number --color=always --highlight-line={2} {1}'
set preview_file 'bat --number --color=always {1}'
set preview_dir 'lsd --blocks=permission,size,name --color=always --tree --depth=2 {1}'
set window 'right,50%,border-left'
if test (math (tput cols) / (tput lines)) -lt 2
set window 'up,66%,border-bottom'
end
set prompt ': '
set pointer '❯'
set marker '+'
# set color 'hl:-1,hl+:-1'
function fd-fzf-file
if not command -q fd
echo "error: fd must be installed"
return 1
end
FZF_DEFAULT_COMMAND="$prefix_file '$argv[1]'" \
fzf --ansi \
--no-bold \
--tabstop=4 \
# --color "$color" \
--prompt "$prompt" \
--pointer "$pointer" \
--marker "$marker" \
--query "$argv[2]" \
--delimiter ':' \
--preview "$preview_file" \
--preview-window "$window" \
--bind "enter:become($EDITOR {1})" \
--bind "ctrl-o:become(open -R {1})"
end
function fd-fzf-dir
if not command -q fd
echo "error: fd must be installed"
return 1
end
FZF_DEFAULT_COMMAND="$prefix_dir '$argv[1]'" \
fzf --ansi \
--no-bold \
--tabstop=4 \
# --color "$color" \
--prompt "$prompt" \
--pointer "$pointer" \
--marker "$marker" \
--query "$argv[2]" \
--delimiter ':' \
--preview "$preview_dir" \
--preview-window "$window" \
--bind "enter:become($EDITOR {1})" \
--bind "ctrl-o:become(open {1})"
end
function ripgrep-fzf
if not command -q rg
echo "error: ripgrep must be installed"
return 1
end
FZF_DEFAULT_COMMAND="$prefix_rg '$argv[1]'" \
fzf --ansi \
--no-bold \
--tabstop=4 \
# --color "$color" \
--prompt "$prompt" \
--pointer "$pointer" \
--marker "$marker" \
--query "$argv[2]" \
--delimiter ':' \
--preview "$preview_rg" \
--preview-window "$window" \
--bind "enter:become($EDITOR {1}:{2}:{3})" \
--bind "ctrl-o:become(open -R {1})"
end
# NOTE: skim already smells like abandonware, and it has unsolved issues, so
# it is not always convenient or even possible to use
function fuzz -d 'Interactive fuzzy finder'
if not command -q fzf
echo "error: fzf must be installed"
return 1
end
set -l opts (fish_opt -s h -l help)
set -a opts (fish_opt -s f -l file)
set -a opts (fish_opt -s d -l dir)
argparse --ignore-unknown --stop-nonopt $opts -- $argv
or return
if test -n "$_flag_help" -o -z "$argv"
echo "Usage: $_ [OPTS...] INIT_QUERY [FZF_QUERY]"
echo ''
echo 'Options:'
echo ' -f, --file Use file name search'
echo ' -d, --dir Use directory name search'
echo ''
echo 'Parameters:'
echo ' INIT_QUERY An initial pre-filtering query'
echo ' FZF_QUERY A fuzzy finder query [optional]'
else if test -n "$_flag_file"
fd-fzf-file $argv
else if test -n "$_flag_dir"
fd-fzf-dir $argv
else
ripgrep-fzf $argv
end
end
end