1
0
Fork 0

Merge pull request #1 from andreyorst/x11

Support X11
This commit is contained in:
Andrey Orst 2018-09-24 12:16:25 +03:00 committed by GitHub
commit 37016b0b04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 40 deletions

View file

@ -10,9 +10,8 @@ want to resource kakrc plugin would not provide any warnings.
Good code:
```kak
define-command -override -hidden -docstring \
define-command -hidden -docstring \
"This is an example of adding new fzf-mode command.
Note that '-override' is used since script should always be resourceable
If shell scripting is involved please follow POSIX standards, and test
your code in POSIX shells, like 'dash', 'ash', and popular POSIX-compatible
shells, like 'bash' and 'zsh' You earn bonus points if your script works in 'fish'.
@ -58,7 +57,7 @@ and fallback to another if not. Is so `fzf` can be called from shell expansion `
Good code:
```kak
define-command -override -hidden -docstring \
define-command -hidden -docstring \
"This is an example of using fzf command from shell expansion.
Note that first argument should be used with escaped '$1'. This is intentional
because you will echo whole command out of shell expansion and without escaping '$1'

View file

@ -3,17 +3,31 @@
**fzf.kak** is a plugin for Kakoune editor, that brings integration with fzf
tool. This plugin is being tested against Kakoune 2018.09.04.
## Installation
This plugin requires Tmux. Support for X11 is planned in the near future.
### Dependencies
Assuming you're using [plug.kak](https://github.com/andreyorst/plug.kak) plugin
manager, add this to your `.kakrc`:
#### tmux
If you're using tmux make sure, that fzf-tmux script is installed and available.
#### X11
Script works with X11 via `termcmd` option, but needs more testing, so think of
it as experimental feature for now.
#### GNU Screen
GNU Screen is not yet supported.
## Installation
Recommended way to install is to use [plug.kak](https://github.com/andreyorst/plug.kak) plugin
manager. You can install **fzf.kak** by adding this to your `kakrc`:
```kak
plug andreyorst/fzf.kak
```
Reload Kakoune config by and run `:plug-install`. Or install this plugin any other preferred way.
Then reload Kakoune config or restart Kakoune and run `:plug-install`.
Or install this plugin any other preferred way.
## Usage

View file

@ -11,21 +11,20 @@
# │ different fzf commands. │
# ╰─────────────────────────────────╯
# New mode
evaluate-commands %sh{ modes="_ "$kak_user_modes; [ -z "${modes##*fzf*}" ] || echo declare-user-mode fzf }
declare-user-mode fzf
# Options
declare-option -docstring "command to provide list of files to fzf.
Supported tools:
find - GNU Find
ag - The Silver Searcher
rg - ripgrep
find - GNU Find
ag - The Silver Searcher
rg - ripgrep
Arguments are also can be passed along with it.
Default arguments are:
find -type f
ag -l -f --hidden --one-device .
rg -L --hidden --files
find -type f
ag -l -f --hidden --one-device .
rg -L --hidden --files
" \
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>'
# Commands
define-command -override -docstring \
define-command -docstring \
"fzf-mode: Enter fzf-mode
This is to be used in mappings to enter fzf-mode
For example: map global normal <c-p> ': fzf-mode<ret>'
" \
fzf-mode %{ evaluate-commands 'enter-user-mode fzf' }
define-command -override -hidden -docstring \
define-command -hidden -docstring \
"fzf-file: Run fzf to open file
Configurable options:
fzf_file_command: command to run with fzf to list possible files.
@ -83,37 +82,40 @@ fzf-file %{
}
}
define-command -override -hidden fzf-git %{
define-command -hidden fzf-git %{
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"
}
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"
}
define-command -override -hidden fzf -params 2 %{ evaluate-commands %sh{
if [ -z "${kak_client_env_TMUX}" ]; then
echo 'fail "client was not started under tmux"'
exit
fi
define-command -hidden fzf -params 2 %{ evaluate-commands %sh{
callback=$1
items_command=$2
tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX))
exec=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-exec.XXXXXX))
callback=$1; shift
items_command=$1; shift
if [ -z $(command -v $(echo $items_command | head -n 1)) ]; then
eval echo fail "\'$(echo $items_command | head -n 1)' executable not found. Is it installed?"
if [ ! -z "${kak_client_env_TMUX}" ]; then
cmd="$items_command | fzf-tmux -d 15 --color=16 > $tmp"
elif [ ! -z "${kak_opt_termcmd}" ]; then
path=$(pwd)
cmd="$kak_opt_termcmd \"sh -c 'cd $path && $items_command | fzf > $tmp'\""
else
echo "fail termcmd option is not set"
fi
items_executable=$(echo $items_command | awk '{print $1}')
if [ -z $(command -v $items_executable) ]; then
eval echo fail "\'$items_executable' executable not found. Is it installed?"
exit
fi
flags='--color=16'
[ -z "${@##* -multi*}" ] && flags="$flags -m"
echo "echo eval -client $kak_client \"$callback\" | kak -p $kak_session" > $exec
chmod 755 $exec
(
eval "$items_command | fzf-tmux -d 15 $flags > $tmp"
eval "$cmd"
(while read file; do
$exec $file
done) < $tmp
@ -122,22 +124,29 @@ define-command -override -hidden fzf -params 2 %{ evaluate-commands %sh{
) > /dev/null 2>&1 < /dev/null &
}}
define-command -override -hidden fzf-buffer %{ evaluate-commands %sh{
if [ -z "${kak_client_env_TMUX}" ]; then
echo 'fail "client was not started under tmux"'
exit
fi
define-command -hidden fzf-buffer %{ evaluate-commands %sh{
tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX))
setbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-setbuf.XXXXXX))
delbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-delbuf.XXXXXX))
buffers=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-buffers.XXXXXX))
items_command="echo $kak_buflist | tr ' ' '\n' | sort"
if [ ! -z "${kak_client_env_TMUX}" ]; then
# cmd="$items_command | fzf-tmux -d 15 --color=16 -e --preview='$setbuf {}' --preview-window=up:hidden --expect ctrl-d > $tmp"
cmd="$items_command | fzf-tmux -d 15 --color=16 --expect ctrl-d > $tmp"
elif [ ! -z "${kak_opt_termcmd}" ]; then
path=$(pwd)
eval "echo $kak_buflist | tr ' ' '\n' | sort > $buffers"
cmd="$kak_opt_termcmd \"sh -c 'cat $buffers | fzf --color=16 --expect ctrl-d > $tmp'\""
else
echo "fail termcmd option is not set"
fi
echo "echo eval -client $kak_client \"buffer \$1\" | kak -p $kak_session" > $setbuf
echo "echo eval -client $kak_client \"delete-buffer \$1\" | kak -p $kak_session" > $delbuf
echo "echo eval -client $kak_client \"fzf-buffer \" | kak -p $kak_session" >> $delbuf
chmod 755 $setbuf
chmod 755 $delbuf
(
eval "echo $kak_buflist | tr ' ' '\n' | sort |
fzf-tmux -d 15 --color=16 -e --preview='$setbuf {}' --preview-window=up:hidden --expect ctrl-d > $tmp"
eval "$cmd"
if [ -s $tmp ]; then
( read action
read buf
@ -153,6 +162,7 @@ define-command -override -hidden fzf-buffer %{ evaluate-commands %sh{
rm $tmp
rm $setbuf
rm $delbuf
rm $buffers
) > /dev/null 2>&1 < /dev/null &
}}