#!/bin/zsh
 
-exec >&2
-fns=()
-toprint=()
 typeset -A seen
-ctr=0
 path-extractor | while read fn ; do
     [[ $seen[$fn] -eq 1 ]] && continue
     seen+=($fn 1)
-    fns+=($fn)
-    toprint+=(`printf "%X:%s" $ctr "${fn}"`)
-    ctr=$(( $ctr + 1 ))
-done
-[[ $ctr -le 20 ]] && print -C 1 $toprint || print -c $toprint
-print -n "> "
-read choice < /dev/tty
-[[ "$choice" = "q" ]] && exit
-if [[ "$choice" = "*" ]]; then
-    buf=$fns
-else
-    buf=()
-    for c in ${=choice} ; do
-        fn=$fns[$(( 1 + 16#$c ))]
-        buf+=($fn)
-    done
-fi
-print $buf
-print -n $buf | xclip -in -selection clipboard
+    print $fn
+done | fzf -m | tr "\n" " " | read data
+tmux set-buffer "$data"
 
 #!/bin/sh
 
 tmux has-session -t path-extractor && tmux kill-session -t path-extractor || :
-tmux new-session -d -s path-extractor "
-    ~/bin/pe < /tmp/tmux-buffer
-    tmux detach
-    sleep 20
-"
+tmux new-session -d -s path-extractor "pe < /tmp/tmux-buffer ; tmux detach"
 tmux set-option -t path-extractor status off
 exec tmux attach-session -t path-extractor
 
     save-buffer /tmp/tmux-buffer
     delete-buffer
     display-popup -KE -w 100% -R "~/bin/tmux-path-extractor.sh"
+    paste-buffer
+    delete-buffer
 }
 
 bind-key Y {
 
 export MYSQL_HISTFILE=/tmp/.mysql_history
 export REDO_JOBS=0 REDO_NO_SYNC=1
 export SHARNESS_TEST_SRCDIR=$HOME/local/stow/sharness/share/sharness
-export FZF_CTRL_T_COMMAND="print -C 1 **~.git/*"
-export FZF_DEFAULT_OPTS="--inline-info"
 # }}}
 
 # }}}
 
 # fzf {{{
+alias -g PE="| pe"
+
+export FZF_DEFAULT_OPTS="--color=16 --info=inline --preview='less -N -S {}'"
+
+_fzf_find() {
+    find . \( -path "*/\.git" -o -fstype devfs -o -fstype procfs \) -prune \
+        -o -type d -print $@ 2>/dev/null | cut -b3-
+}
+
+export FZF_CTRL_T_COMMAND="_fzf_find -o -type f -print -o -type l -print"
+export FZF_ALT_C_COMMAND=_fzf_find
+
 . ~/work/fzf/shell/key-bindings.zsh
 # }}}