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: Good code:
```kak ```kak
define-command -override -hidden -docstring \ define-command -hidden -docstring \
"This is an example of adding new fzf-mode command. "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 If shell scripting is involved please follow POSIX standards, and test
your code in POSIX shells, like 'dash', 'ash', and popular POSIX-compatible 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'. 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: Good code:
```kak ```kak
define-command -override -hidden -docstring \ define-command -hidden -docstring \
"This is an example of using fzf command from shell expansion. "This is an example of using fzf command from shell expansion.
Note that first argument should be used with escaped '$1'. This is intentional 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' 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 **fzf.kak** is a plugin for Kakoune editor, that brings integration with fzf
tool. This plugin is being tested against Kakoune 2018.09.04. tool. This plugin is being tested against Kakoune 2018.09.04.
## Installation ### Dependencies
This plugin requires Tmux. Support for X11 is planned in the near future.
Assuming you're using [plug.kak](https://github.com/andreyorst/plug.kak) plugin #### tmux
manager, add this to your `.kakrc`: 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 ```kak
plug andreyorst/fzf.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 ## Usage

View file

@ -11,8 +11,7 @@
# │ 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.
@ -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,40 @@ 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
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 if [ ! -z "${kak_client_env_TMUX}" ]; then
items_command=$1; shift cmd="$items_command | fzf-tmux -d 15 --color=16 > $tmp"
if [ -z $(command -v $(echo $items_command | head -n 1)) ]; then elif [ ! -z "${kak_opt_termcmd}" ]; then
eval echo fail "\'$(echo $items_command | head -n 1)' executable not found. Is it installed?" 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 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"
(while read file; do (while read file; do
$exec $file $exec $file
done) < $tmp done) < $tmp
@ -122,22 +124,29 @@ 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
echo 'fail "client was not started under tmux"'
exit
fi
tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX)) tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX))
setbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-setbuf.XXXXXX)) setbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-setbuf.XXXXXX))
delbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-delbuf.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 \"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 \"delete-buffer \$1\" | kak -p $kak_session" > $delbuf
echo "echo eval -client $kak_client \"fzf-buffer \" | kak -p $kak_session" >> $delbuf echo "echo eval -client $kak_client \"fzf-buffer \" | kak -p $kak_session" >> $delbuf
chmod 755 $setbuf chmod 755 $setbuf
chmod 755 $delbuf chmod 755 $delbuf
( (
eval "echo $kak_buflist | tr ' ' '\n' | sort | eval "$cmd"
fzf-tmux -d 15 --color=16 -e --preview='$setbuf {}' --preview-window=up:hidden --expect ctrl-d > $tmp"
if [ -s $tmp ]; then if [ -s $tmp ]; then
( read action ( read action
read buf read buf
@ -153,6 +162,7 @@ define-command -override -hidden fzf-buffer %{ evaluate-commands %sh{
rm $tmp rm $tmp
rm $setbuf rm $setbuf
rm $delbuf rm $delbuf
rm $buffers
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
}} }}