1
0
Fork 0

move fzf commands to submodules

This commit is contained in:
Andrey Orst 2018-11-11 13:41:15 +03:00
parent f7c94f9b7e
commit 08018d5386
11 changed files with 1582 additions and 1483 deletions

View file

@ -0,0 +1,32 @@
# ╭─────────────╥─────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩═════════════════════════╡
# │ Submodule for Bzr support for fzf.kak │
# ╞═══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰───────────────────────────────────────╯
declare-option -docstring "command to provide list of files in GNU Bazaar repository to fzf. Arguments are supported
Supported tools:
<package>: <value>:
GNU Bazaar: ""bzr""
Default arguments:
""bzr ls -R --versioned -0""
" \
str fzf_bzr_command "bzr"
map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' '<esc>: fzf-bzr<ret>'
define-command -hidden fzf-bzr %{ evaluate-commands %sh{
case $kak_opt_fzf_bzr_command in
bzr)
cmd="bzr ls -R --versioned -0" ;;
bzr*)
cmd=$kak_opt_fzf_bzr_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
echo "fzf %{edit \$1} %{$cmd} %{-m --expect ctrl-w $additional_flags}"
}}

View file

@ -0,0 +1,32 @@
# ╭─────────────╥─────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩═════════════════════════╡
# │ Submodule for Git support for fzf.kak │
# ╞═══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰───────────────────────────────────────╯
declare-option -docstring "command to provide list of files in git tree to fzf. Arguments are supported
Supported tools:
<package>: <value>:
Git : ""git""
Default arguments:
""git ls-tree --name-only -r HEAD""
" \
str fzf_git_command "git"
map global fzf-vcs -docstring "edit file from Git tree" 'g' '<esc>: fzf-git<ret>'
define-command -hidden fzf-git %{ evaluate-commands %sh{
case $kak_opt_fzf_git_command in
git)
cmd="git ls-tree --name-only -r HEAD" ;;
git*)
cmd=$kak_opt_fzf_git_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
echo "fzf %{edit \$1} %{$cmd} %{-m --expect ctrl-w $additional_flags}"
}}

View file

@ -0,0 +1,32 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩════════════════════════╡
# │ Submodule for Hg support for fzf.kak │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
declare-option -docstring "command to provide list of files in mercurial repository to fzf. Arguments are supported
Supported tools:
<package>: <value>:
Mercurial SCM: ""hg""
Default arguments:
""hg locate -f -0 -I .hg locate -f -0 -I .""
" \
str fzf_hg_command "hg"
map global fzf-vcs -docstring "edit file from mercurial tree" 'h' '<esc>: fzf-hg<ret>'
define-command -hidden fzf-hg %{ evaluate-commands %sh{
case $kak_opt_fzf_hg_command in
hg)
cmd="hg locate -f -0 -I .hg locate -f -0 -I ." ;;
hg*)
cmd=$kak_opt_fzf_hg_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
echo "fzf %{edit \$1} %{$cmd} %{-m --expect ctrl-w $additional_flags}"
}}

View file

@ -0,0 +1,32 @@
# ╭─────────────╥─────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩═════════════════════════╡
# │ Submodule for SVN support for fzf.kak │
# ╞═══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰───────────────────────────────────────╯
declare-option -docstring "command to provide list of files in svn repository to fzf. Arguments are supported
Supported tools:
<package>: <value>:
Subversion: ""svn""
Default arguments:
""svn list -R . | grep -v '$/' | tr '\\n' '\\0'""
" \
str fzf_svn_command "svn"
map global fzf-vcs -docstring "edit file from Subversion tree" 's' '<esc>: fzf-svn<ret>'
define-command -hidden fzf-svn %{ evaluate-commands %sh{
case $kak_opt_fzf_svn_command in
svn)
cmd="svn list -R . | grep -v '$/' | tr '\\n' '\\0'" ;;
svn*)
cmd=$kak_opt_fzf_svn_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
echo "fzf %{edit \$1} %{$cmd} %{-m --expect ctrl-w $additional_flags}"
}}

View file

@ -0,0 +1,59 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-buffer.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for changing buffers with fzf │
# │ for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
map global fzf -docstring "open buffer" 'b' '<esc>: fzf-buffer<ret>'
define-command -hidden fzf-buffer %{ evaluate-commands %sh{
tmp=$(mktemp $(eval echo ${TMPDIR:-/tmp}/kak-fzf.XXXXXX))
setbuf=$(mktemp $(eval echo ${TMPDIR:-/tmp}/kak-setbuf.XXXXXX))
delbuf=$(mktemp $(eval echo ${TMPDIR:-/tmp}/kak-delbuf.XXXXXX))
buffers=$(mktemp $(eval echo ${TMPDIR:-/tmp}/kak-buffers.XXXXXX))
IFS="'"
for buffer in $kak_buflist; do
[ ! -z $buffer ] && [ $buffer != ' ' ] && echo $buffer >> $buffers
done
if [ ! -z "${kak_client_env_TMUX}" ]; then
cmd="cat $buffers | fzf-tmux -d $kak_opt_fzf_tmux_height --expect ctrl-d > $tmp"
elif [ ! -z "${kak_opt_termcmd}" ]; then
cmd="$kak_opt_termcmd \"sh -c 'cat $buffers | fzf --expect ctrl-d > $tmp'\""
else
echo "fail termcmd option is not set"
fi
echo "info -title 'fzf buffer' 'Set buffer to edit in current client
<c-d>: delete selected buffer'"
echo "echo evaluate-commands -client $kak_client \"buffer \'\$1'\" | kak -p $kak_session" > $setbuf
echo "echo evaluate-commands -client $kak_client \"delete-buffer \'\$1'\" | kak -p $kak_session" > $delbuf
echo "echo evaluate-commands -client $kak_client \"fzf-buffer \" | kak -p $kak_session" >> $delbuf
chmod 755 $setbuf
chmod 755 $delbuf
(
eval "$cmd"
if [ -s $tmp ]; then
(
read action
read buf
if [ "$action" = "ctrl-d" ]; then
$setbuf $kak_bufname
$delbuf $buf
else
$setbuf $buf
fi
) < $tmp
else
$setbuf $kak_bufname
fi
rm $tmp
rm $setbuf
rm $delbuf
rm $buffers
) > /dev/null 2>&1 < /dev/null &
}}

31
rc/fzf-modules/fzf-cd.kak Normal file
View file

@ -0,0 +1,31 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-cd.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for changing directories with │
# │ fzf for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
declare-option -docstring "command to provide list of directories to fzf.
Default value:
find: (echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)
" \
str fzf_cd_command "find"
map global fzf -docstring "change directory" 'c' '<esc>: fzf-cd<ret>'
define-command -hidden fzf-cd %{ evaluate-commands %sh{
title="fzf change directory"
message="Change the server''s working directory"
echo "info -title '$title' '$message'"
case $kak_opt_fzf_cd_command in
find)
cmd="(echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
*)
cmd=$kak_opt_fzf_cd_command ;;
esac
echo "fzf %{change-directory \$1} %{$cmd}"
}}

1223
rc/fzf-modules/fzf-ctags.kak Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,61 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-file.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for opening files with fzf │
# │ for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
declare-option -docstring "command to provide list of files to fzf. Arguments are supported
Supported tools:
<package>: <value>:
GNU Find: ""find""
The Silver Searcher: ""ag""
ripgrep: ""rg""
fd: ""fd""
Default arguments:
find: ""find -type f -follow""
ag: ""ag -l -f --hidden --one-device .""
rg: ""rg -L --hidden --files""
fd: ""fd --type f --follow""
" \
str fzf_file_command "find"
map global fzf -docstring "open file" 'f' '<esc>: fzf-file<ret>'
define-command -hidden fzf-file %{ evaluate-commands %sh{
if [ -z $(command -v $kak_opt_fzf_file_command) ]; then
echo "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''"
kak_opt_fzf_file_command="find"
fi
case $kak_opt_fzf_file_command in
find)
cmd="find -type f -follow" ;;
ag)
cmd="ag -l -f --hidden --one-device . " ;;
rg)
cmd="rg -L --hidden --files" ;;
fd)
cmd="fd --type f --follow" ;;
find*|ag*|rg*|fd*)
cmd=$kak_opt_fzf_file_command ;;
*)
executable=$(echo $kak_opt_fzf_file_command | awk '{print $1'}| tr '(' ' ' | cut -d " " -f 2)
echo "echo -markup '{Information}''$executable'' is not supported by the script. fzf.kak may not work as you expect.'"
cmd=$kak_opt_fzf_file_command ;;
esac
title="fzf file"
[ ! -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.
<ret>: open file in new buffer.
<c-w>: open file in new window $additional_keybindings"
echo "info -title '$title' '$message'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
echo "fzf %{edit \$1} %{$cmd} %{-m --expect ctrl-w $additional_flags}"
}}

View file

@ -0,0 +1,24 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-search.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for searching inside current │
# │ buffer with fzf for fzf.kak │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
map global fzf -docstring "search in buffer" 's' '<esc>: fzf-buffer-search<ret>'
define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
title="fzf buffer search"
message="Search buffer with fzf, and jump to result location"
echo "info -title '$title' '$message'"
line=$kak_cursor_line
char=$(expr $kak_cursor_char_column - 1)
buffer_content=$(mktemp ${TMPDIR:-/tmp}/kak-curr-buff.XXXXXX)
echo "execute-keys %{%<a-|>cat<space>><space>$buffer_content<ret>;}"
echo "execute-keys $line g $char l"
echo "fzf %{execute-keys \$1 gx} %{(nl -b a -n ln $buffer_content} %{--reverse | cut -f 1; rm $buffer_content)}"
}}

View file

@ -0,0 +1,56 @@
# ╭─────────────╥────────────────────────╮
# │ 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 │
# ╰──────────────────────────────────────╯
try %{ declare-user-mode fzf-vcs } catch %{echo -markup "{Error}Can't declare mode 'fzf-vcs' - already exists"}
map global fzf -docstring "edit file from vcs repo" 'v' '<esc>: fzf-vcs<ret>'
map global fzf -docstring "svitch to vcs selection mode" 'V' '<esc>: fzf-vcs-mode<ret>'
define-command -docstring "Enter fzf-vcs-mode.
This mode allows selecting specific vcs command." \
fzf-vcs-mode %{ try %{ evaluate-commands 'enter-user-mode fzf-vcs' } }
define-command -hidden -docstring "Wrapper command for fzf vcs to automatically decect
used version control system.
Supported vcs:
Git: ""git""
Subversion: ""svn""
Mercurial SCM: ""hg""
GNU Bazaar: ""bzr""
" \
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
vcs=$(echo $cmd | awk '{print $1}')
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.
<c-w>: open file in new window $additional_keybindings"
echo "info -title '$title' '$message'"
echo "fzf-$vcs"
exit
fi
done
echo "echo -markup '{Information}No VCS found in current folder'"
}}

1483
rc/fzf.kak

File diff suppressed because it is too large Load diff