2021-03-19 18:00:49 +00:00
|
|
|
# Author: Andrey Listopadov
|
|
|
|
# Module for changing directories with fzf for fzf.kak plugin
|
|
|
|
# https://github.com/andreyorst/fzf.kak
|
|
|
|
|
|
|
|
hook global ModuleLoaded fzf %{
|
|
|
|
map global fzf -docstring "change directory" 'c' '<esc>: require-module fzf-cd; fzf-cd<ret>'
|
|
|
|
}
|
|
|
|
|
|
|
|
provide-module fzf-cd %§
|
2019-10-04 13:24:44 +00:00
|
|
|
|
2018-11-11 10:41:15 +00:00
|
|
|
declare-option -docstring "command to provide list of directories to fzf.
|
|
|
|
Default value:
|
2019-02-15 17:11:45 +00:00
|
|
|
find: (echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)
|
2018-11-11 10:41:15 +00:00
|
|
|
" \
|
|
|
|
str fzf_cd_command "find"
|
|
|
|
|
2018-11-29 11:33:33 +00:00
|
|
|
declare-option -docstring 'allow showing preview window while changing directories
|
|
|
|
Default value:
|
|
|
|
false
|
|
|
|
' \
|
|
|
|
bool fzf_cd_preview false
|
|
|
|
|
|
|
|
declare-option -docstring 'command to show list of directories in preview window
|
|
|
|
Default value:
|
|
|
|
tree -d
|
|
|
|
' \
|
2019-07-17 05:53:36 +00:00
|
|
|
str cd_preview_command "tree -d {}"
|
2018-11-29 11:33:33 +00:00
|
|
|
|
|
|
|
declare-option -docstring 'maximum amount of previewed directories' \
|
|
|
|
int fzf_preview_dirs '300'
|
|
|
|
|
2018-11-11 10:41:15 +00:00
|
|
|
define-command -hidden fzf-cd %{ evaluate-commands %sh{
|
2019-03-27 11:54:12 +00:00
|
|
|
printf '%s\n' "info -title %{fzf change directory} %{Change the server's working directory
|
|
|
|
current path: $(pwd)}"
|
2021-03-20 19:44:19 +00:00
|
|
|
case ${kak_opt_fzf_cd_command:-} in
|
2019-07-07 08:27:37 +00:00
|
|
|
(find) items_command="(echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
|
|
|
|
(*) items_command=$kak_opt_fzf_cd_command ;;
|
2018-11-22 12:36:32 +00:00
|
|
|
esac
|
2021-03-20 19:44:19 +00:00
|
|
|
if [ "${kak_opt_fzf_cd_preview:-}" = "true" ]; then
|
2019-03-26 18:04:28 +00:00
|
|
|
preview_flag="-preview"
|
2021-03-20 19:44:19 +00:00
|
|
|
preview="--preview '(${kak_opt_cd_preview_command:-}) 2>/dev/null | head -n ${kak_opt_fzf_preview_dirs:-0}'"
|
2018-11-29 11:33:33 +00:00
|
|
|
fi
|
2019-03-26 18:04:28 +00:00
|
|
|
printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}"
|
2018-11-22 12:36:32 +00:00
|
|
|
}}
|
2018-11-24 11:39:54 +00:00
|
|
|
|
2019-05-09 15:12:06 +00:00
|
|
|
§
|