fzf: fix fzf-file-widget, improve template

fzf-file-widget had several mistakes:

1) It was missing zsh -c for the tmux command to run
2) the fsel function wasn't accessible from the shell we spawned in the
new tmux pane

We solved the second issue by converting the function to an executable
fzf-fsel. We also patched the bash key bindings to make use of that
executable.

While we were at it, we improved the template by setting wrksrc
correctly and cd'ing in pre_build.
This commit is contained in:
Dominik Honnef 2015-04-18 05:21:23 +02:00
parent 2845b97c5e
commit bc693d1375
4 changed files with 46 additions and 28 deletions

View file

@ -1,27 +1,13 @@
fzf-file-widget_fsel() {
command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 1d | cut -b3- | fzf -m | while read item; do
printf '%q ' "$item"
done
echo
}
fzf-file-widget() {
if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then
local height
height=${FZF_TMUX_HEIGHT:-40%}
if [[ $height =~ %$ ]]; then
height="-p ${height%\%}"
else
height="-l $height"
fi
tmux split-window $height "cd $(printf %q "$PWD"); tmux send-keys -t $TMUX_PANE \"\$(fzf-file-widget_fsel)\"'"
if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then
local height
height=${FZF_TMUX_HEIGHT:-40%}
if [[ $height =~ %$ ]]; then
height="-p ${height%\%}"
else
LBUFFER="${LBUFFER}$(fzf-file-widget_fsel)"
zle redisplay
height="-l $height"
fi
}
fzf-file-widget "$@"
tmux split-window $height "cd $(printf %q "$PWD"); zsh -c 'tmux send-keys -t $TMUX_PANE \"\$(fzf-fsel)\"'"
else
LBUFFER="${LBUFFER}$(fzf-fsel)"
zle redisplay
fi

View file

@ -0,0 +1,8 @@
#!/bin/sh
command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 1d | cut -b3- | fzf -m | while read item; do
printf '%q ' "$item"
done
echo

View file

@ -0,0 +1,18 @@
--- shell/key-bindings.bash.orig 2015-04-18 05:12:24.372078942 +0200
+++ shell/key-bindings.bash 2015-04-18 05:12:49.244078057 +0200
@@ -1,15 +1,5 @@
# Key bindings
# ------------
-__fsel() {
- command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
- -o -type f -print \
- -o -type d -print \
- -o -type l -print 2> /dev/null | sed 1d | cut -b3- | fzf -m | while read item; do
- printf '%q ' "$item"
- done
- echo
-}
-
if [[ $- =~ i ]]; then
__fsel_tmux() {

View file

@ -2,8 +2,8 @@
pkgname=fzf
version=0.9.7.1
_version=0.9.7-1
wrksrc=${pkgname}-${_version}/src
revision=1
wrksrc=${pkgname}-${_version}
revision=2
build_style=go
go_import_path="github.com/junegunn/fzf/src"
go_package="github.com/junegunn/fzf/src/fzf"
@ -19,12 +19,18 @@ checksum=38fa16c41e861af6ad87e7ff655188559775a2979254d76198c435d198e15fb4
# Needs cgo to build, which doesn't work when cross-compiling.
nocross=yes
pre_build() {
cd src
}
post_install() {
cd ${wrksrc}/..
cd ${wrksrc}
vbin bin/fzf-tmux
vbin ${FILESDIR}/fzf-fsel
vman man/man1/fzf.1
sed -i -e 's#source ~/\.fzf\.bash; ##' shell/key-bindings.bash
sed -i -e 's/(__fsel)/(fzf-fsel)/' shell/key-bindings.bash
vinstall plugin/fzf.vim 644 usr/share/vim/vimfiles/plugin
vinstall shell/completion.bash 644 usr/share/bash-completion/completions fzf
vinstall ${FILESDIR}/fzf-file-widget 644 usr/share/zsh/site-functions