1
0
Fork 0

WIP x11 support

This commit is contained in:
andreyorst 2018-09-24 10:37:45 +03:00
parent 8381d831cc
commit d855e32b90

View file

@ -11,21 +11,20 @@
# │ different fzf commands. │ # │ different fzf commands. │
# ╰─────────────────────────────────╯ # ╰─────────────────────────────────╯
# New mode declare-user-mode fzf
evaluate-commands %sh{ modes="_ "$kak_user_modes; [ -z "${modes##*fzf*}" ] || echo declare-user-mode fzf }
# Options # Options
declare-option -docstring "command to provide list of files to fzf. declare-option -docstring "command to provide list of files to fzf.
Supported tools: Supported tools:
find - GNU Find find - GNU Find
ag - The Silver Searcher ag - The Silver Searcher
rg - ripgrep rg - ripgrep
Arguments are also can be passed along with it. Arguments are also can be passed along with it.
Default arguments are: Default arguments are:
find -type f find -type f
ag -l -f --hidden --one-device . ag -l -f --hidden --one-device .
rg -L --hidden --files rg -L --hidden --files
" \ " \
str fzf_file_command "find" str fzf_file_command "find"
@ -43,14 +42,14 @@ map global fzf -docstring "change directory" c '<esc>: fzf-cd<ret>'
map global fzf -docstring "edif file in git tree" g '<esc>: fzf-git<ret>' map global fzf -docstring "edif file in git tree" g '<esc>: fzf-git<ret>'
# Commands # Commands
define-command -override -docstring \ define-command -docstring \
"fzf-mode: Enter fzf-mode "fzf-mode: Enter fzf-mode
This is to be used in mappings to enter fzf-mode This is to be used in mappings to enter fzf-mode
For example: map global normal <c-p> ': fzf-mode<ret>' For example: map global normal <c-p> ': fzf-mode<ret>'
" \ " \
fzf-mode %{ evaluate-commands 'enter-user-mode fzf' } fzf-mode %{ evaluate-commands 'enter-user-mode fzf' }
define-command -override -hidden -docstring \ define-command -hidden -docstring \
"fzf-file: Run fzf to open file "fzf-file: Run fzf to open file
Configurable options: Configurable options:
fzf_file_command: command to run with fzf to list possible files. fzf_file_command: command to run with fzf to list possible files.
@ -83,37 +82,41 @@ fzf-file %{
} }
} }
define-command -override -hidden fzf-git %{ define-command -hidden fzf-git %{
fzf "edit $1" "git ls-tree --name-only -r HEAD" fzf "edit $1" "git ls-tree --name-only -r HEAD"
} }
define-command -override -hidden fzf-tag %{ define-command -hidden fzf-tag %{
fzf "ctags-search $1" "readtags -l | cut -f1 | sort -u" fzf "ctags-search $1" "readtags -l | cut -f1 | sort -u"
} }
define-command -override -hidden fzf-cd %{ define-command -hidden fzf-cd %{
fzf "change-directory $1" "find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print" fzf "change-directory $1" "find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print"
} }
define-command -override -hidden fzf -params 2 %{ evaluate-commands %sh{ define-command -hidden fzf -params 2 %{ evaluate-commands %sh{
if [ -z "${kak_client_env_TMUX}" ]; then callback=$1
echo 'fail "client was not started under tmux"' items_command=$2
exit if [ ! -z "${kak_client_env_TMUX}" ]; then
cmd="$items_command | fzf-tmux -d 15 --color=16"
fi
if [ ! -z "${kak_opt_termcmd}" ]; then
cmd="$kak_opt_termcmd \"sh -c '$items_command | fzf'\""
else
echo "fail termcmd option is not set"
# exit
fi fi
tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX)) tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX))
exec=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-exec.XXXXXX)) exec=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-exec.XXXXXX))
callback=$1; shift items_executable=$(echo $items_command | awk '{print $1}')
items_command=$1; shift if [ -z $(command -v $items_executable) ]; then
if [ -z $(command -v $(echo $items_command | head -n 1)) ]; then eval echo fail "\'$items_executable' executable not found. Is it installed?"
eval echo fail "\'$(echo $items_command | head -n 1)' executable not found. Is it installed?"
exit exit
fi fi
flags='--color=16'
[ -z "${@##* -multi*}" ] && flags="$flags -m"
echo "echo eval -client $kak_client \"$callback\" | kak -p $kak_session" > $exec echo "echo eval -client $kak_client \"$callback\" | kak -p $kak_session" > $exec
chmod 755 $exec chmod 755 $exec
( (
eval "$items_command | fzf-tmux -d 15 $flags > $tmp" eval "$cmd > $tmp"
(while read file; do (while read file; do
$exec $file $exec $file
done) < $tmp done) < $tmp
@ -122,7 +125,7 @@ define-command -override -hidden fzf -params 2 %{ evaluate-commands %sh{
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
}} }}
define-command -override -hidden fzf-buffer %{ evaluate-commands %sh{ define-command -hidden fzf-buffer %{ evaluate-commands %sh{
if [ -z "${kak_client_env_TMUX}" ]; then if [ -z "${kak_client_env_TMUX}" ]; then
echo 'fail "client was not started under tmux"' echo 'fail "client was not started under tmux"'
exit exit