1
0
Fork 0
fzf.kak/rc/modules/fzf-vcs.kak

56 lines
1.7 KiB
Text
Raw Normal View History

2021-03-19 18:00:49 +00:00
# Author: Andrey Listopadov
# Module that declares VCS submodule for various version control systems to open files with fzf
# https://github.com/andreyorst/fzf.kak
2018-11-11 10:41:15 +00:00
hook global ModuleLoaded fzf %§
2021-03-19 18:00:49 +00:00
map global fzf -docstring "edit file from vcs repo" 'v' '<esc>: require-module fzf-vcs; fzf-vcs<ret>'
map global fzf -docstring "switch to vcs selection mode" '<a-v>' '<esc>: require-module fzf-vcs; enter-user-mode fzf-vcs<ret>'
2019-05-09 15:12:06 +00:00
§
2021-03-19 18:00:49 +00:00
provide-module fzf-vcs %§
require-module fzf-git
require-module fzf-svn
require-module fzf-hg
require-module fzf-bzr
2019-05-09 15:12:06 +00:00
declare-user-mode fzf-vcs
2018-11-11 10:41:15 +00:00
define-command -hidden -docstring 'Wrapper command for fzf vcs to automatically decect
2018-11-11 10:41:15 +00:00
used version control system.
Supported vcs:
Git: "git"
Subversion: "svn"
Mercurial SCM: "hg"
GNU Bazaar: "bzr"
' \
2018-11-11 10:41:15 +00:00
fzf-vcs %{ evaluate-commands %sh{
commands="git rev-parse --is-inside-work-tree
svn info
hg --cwd . root
bzr status"
IFS='
'
for cmd in $commands; do
2021-03-20 19:44:19 +00:00
eval "$cmd" >/dev/null 2>&1
2018-11-11 10:41:15 +00:00
res=$?
if [ "$res" = "0" ]; then
2018-11-22 12:36:11 +00:00
vcs=$(printf "%s\n" "$cmd" | awk '{print $1}')
2018-11-11 10:41:15 +00:00
title="fzf $vcs"
2021-03-20 19:44:19 +00:00
[ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings="
2021-03-21 10:33:27 +00:00
${kak_opt_fzf_horizontal_map:-ctrl-s}: open file in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open file in vertical split"
2018-11-11 10:41:15 +00:00
message="Open single or multiple files from git tree.
<ret>: open file in new buffer.
2021-03-21 10:33:27 +00:00
${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal $additional_keybindings"
2018-11-22 12:36:11 +00:00
printf "%s\n" "info -title %{$title} %{$message}"
printf "%s\n" "fzf-$vcs"
2018-11-11 10:41:15 +00:00
exit
fi
done
2018-11-22 12:36:11 +00:00
printf "%s\n" "echo -markup '{Information}No VCS found in current folder'"
2018-11-11 10:41:15 +00:00
}}
2019-05-09 15:12:06 +00:00
§