forked from lenormf/kakoune-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfzy.kak
80 lines (71 loc) · 2.91 KB
/
fzy.kak
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
##
## fzy.kak by lenormf
## Support function for the `fzy` utility
## https://github.com/jhawthorn/fzy
##
# `fzy-cached` requires `find-parent-file` in `utils.kak`
decl -docstring %{formatted shell command whose output is passed to `fzy` to generate a list of tokens
Each occurence of the `%s` string will be replaced with the directory to list} \
str fzy_filesearch_cmd 'ag -g "" "%s"'
decl -docstring "options passed to `fzy` when listing a directory" \
str fzy_options '-l $(tput lines)'
decl -docstring "name of the cache filename looked for by the `fzy-cached` command" \
str fzy_cache_filename 'paths'
decl -hidden str fzy_cache_path
def -params .. -file-completion \
-docstring %{fzy [<dirs>]: open a file in the given directories
If no directories are given then the directory in which the current buffer was saved is used} \
fzy %{ %sh{
cmd_multiplexer=""
if [ -n "${DVTM_CMD_FIFO}" ]; then
cmd_multiplexer="fzy-dvtm"
elif [ -n "${TMUX}" ]; then
cmd_multiplexer="fzy-tmux"
else
printf 'echo -color Error This function must be run in a `dvtm` or `tmux` session\n'
exit 1
fi
if [ $# -ge 1 ]; then
cwd=$(printf %s "$*" | sed 's/\//\\\//g')
else
cwd=$(dirname "${kak_buffile}" | sed 's/\//\\\//g')
fi
filesearch_cmd=$(printf %s "${kak_opt_fzy_filesearch_cmd}" | sed "s/%s/${cwd}/g")
eval "${filesearch_cmd}" | eval "'${cmd_multiplexer}' ${kak_opt_fzy_options}" | while read path; do
printf "eval -try-client '%s' edit '%s'" "${kak_client}" "${path}" \
| kak -p "${kak_session}"
done
} }
def -params .. -file-completion \
-docstring %{fzy-cached [<dirs>] open a file in the given cached directories
If no directories are given then the directory in which the current buffer was saved is used} \
fzy-cached %{
%sh{
if [ -z "${DVTM_CMD_FIFO}" ] && [ -z "${TMUX}" ]; then
printf 'echo -color Error This function must be run in a `dvtm` or `tmux` session\n'
exit 1
fi
if [ $# -lt 0 ]; then
printf %s\\n "find-parent-file %opt{fzy_cache_filename} global:fzy_cache_path 0 $@"
else
basedir=$(dirname "${kak_buffile}")
printf %s\\n "find-parent-file %opt{fzy_cache_filename} global:fzy_cache_path 0 ${basedir}"
fi
}
%sh{
if [ -z "${kak_opt_fzy_cache_path}" ]; then
exit
fi
cmd_multiplexer=""
if [ -n "${DVTM_CMD_FIFO}" ]; then
cmd_multiplexer="fzy-dvtm"
elif [ -n "${TMUX}" ]; then
cmd_multiplexer="fzy-tmux"
fi
paths_dir=$(dirname "${kak_opt_fzy_cache_path}")
eval "'${cmd_multiplexer}' ${kak_opt_fzy_options}" < "${kak_opt_fzy_cache_path}" | while read path; do
printf "eval -try-client '%s' edit '%s'" "${kak_client}" "${paths_dir}/${path}" \
| kak -p "${kak_session}"
done
}
}