2018-11-11 10:41:15 +00:00
|
|
|
# ╭─────────────╥────────────────────────╮
|
|
|
|
# │ Author: ║ File: │
|
|
|
|
# │ Andrey Orst ║ fzf-vcs.kak │
|
|
|
|
# ╞═════════════╩════════════════════════╡
|
|
|
|
# │ Module that declares VCS submodule │
|
|
|
|
# │ for various version control systems │
|
|
|
|
# │ to open files with fzf │
|
|
|
|
# ╞══════════════════════════════════════╡
|
|
|
|
# │ GitHub.com/andreyorst/fzf.kak │
|
|
|
|
# ╰──────────────────────────────────────╯
|
|
|
|
|
2019-05-09 15:12:06 +00:00
|
|
|
hook global ModuleLoad fzf %§
|
2018-11-11 10:41:15 +00:00
|
|
|
|
2019-05-09 15:12:06 +00:00
|
|
|
map global fzf -docstring "edit file from vcs repo" 'v' '<esc>: require-module fzf_vcs; fzf-vcs<ret>'
|
2018-11-22 17:29:46 +00:00
|
|
|
map global fzf -docstring "svitch to vcs selection mode" '<a-v>' '<esc>: fzf-vcs-mode<ret>'
|
2018-11-11 10:41:15 +00:00
|
|
|
|
|
|
|
define-command -docstring "Enter fzf-vcs-mode.
|
|
|
|
This mode allows selecting specific vcs command." \
|
2019-05-09 15:12:06 +00:00
|
|
|
fzf-vcs-mode %{ require-module fzf_vcs; evaluate-commands 'enter-user-mode fzf-vcs' }
|
|
|
|
|
|
|
|
§
|
|
|
|
|
|
|
|
provide-module fzf_vcs %§
|
|
|
|
|
|
|
|
declare-user-mode fzf-vcs
|
2018-11-11 10:41:15 +00:00
|
|
|
|
2018-11-22 17:29:46 +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:
|
2018-11-22 17:29:46 +00:00
|
|
|
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
|
|
|
|
eval $cmd >/dev/null 2>&1
|
|
|
|
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"
|
|
|
|
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
|
|
|
|
<c-s>: open file in horizontal split
|
|
|
|
<c-v>: open file in vertical split"
|
|
|
|
message="Open single or multiple files from git tree.
|
|
|
|
<ret>: open file in new buffer.
|
2019-03-28 05:38:38 +00:00
|
|
|
<c-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
|
|
|
§
|