This repository has been archived by the owner on Jun 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
fzf.kak
68 lines (60 loc) · 2.6 KB
/
fzf.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
##
## fzf.kak by lenormf
## Support function for the `fzf` utility
## https://github.com/junegunn/fzf
##
# `fzf-cached` requires `find-parent-file` in `utils.kak`
declare-option -docstring %{formatted shell command whose output is passed to `fzf` to generate a list of tokens
Each occurence of the `%s` string will be replaced with the directory to list} \
str fzf_filesearch_cmd 'ag -g "" "%s"'
declare-option -docstring "options passed to `fzf` when listing a directory" \
str fzf_options '-m'
declare-option -docstring "name of the cache filename looked for by the `fzf-cached` command" \
str fzf_cache_filename 'paths'
declare-option -hidden str fzf_cache_path
define-command -params .. -file-completion \
-docstring %{fzf [<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} \
fzf %{ evaluate-commands %sh{
if [ -z "${TMUX}" ]; then
printf 'echo -color Error This function must be run in a `tmux` session\n'
exit
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_fzf_filesearch_cmd}" | sed "s/%s/${cwd}/g")
eval "${filesearch_cmd}" | eval "fzf-tmux ${kak_opt_fzf_options}" | while read path; do
printf "eval -try-client '%s' edit '%s'" "${kak_client}" "${path}" \
| kak -p "${kak_session}"
done
} }
define-command -params .. -file-completion \
-docstring %{fzf-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} \
fzf-cached %{
evaluate-commands %sh{
if [ -z "${TMUX}" ]; then
printf 'echo -color Error This function must be run in a `tmux` session\n'
exit
fi
if [ $# -lt 0 ]; then
printf %s\\n "find-parent-file %opt{fzf_cache_filename} global:fzf_cache_path 0 $@"
else
basedir=$(dirname "${kak_buffile}")
printf %s\\n "find-parent-file %opt{fzf_cache_filename} global:fzf_cache_path 0 ${basedir}"
fi
}
evaluate-commands %sh{
if [ -z "${kak_opt_fzf_cache_path}" ]; then
exit
fi
paths_dir=$(dirname "${kak_opt_fzf_cache_path}")
eval "fzf-tmux ${kak_opt_fzf_options}" < "${kak_opt_fzf_cache_path}" | while read path; do
printf "eval -try-client '%s' edit '%s'" "${kak_client}" "${paths_dir}/${path}" \
| kak -p "${kak_session}"
done
}
}