mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-02-02 20:18:31 +00:00
[fish] Fix fish key binding issues (#60)
Although a major overhaul is ongoing (#67), it is not yet finished and cannot be considered stable enough for the next release. This commit fixes a few apparent issues with small change to the current implementation. - Fixed error when $TMPDIR is not defined - Better escaping of file/directory names - Splitted functions to workaround fish bug
This commit is contained in:
parent
4e2a1fe5c8
commit
daf08f801f
52
install
52
install
@ -250,46 +250,58 @@ EOFZF
|
|||||||
echo -n "Generate ~/.config/fish/functions/fzf_key_bindings.fish ... "
|
echo -n "Generate ~/.config/fish/functions/fzf_key_bindings.fish ... "
|
||||||
cat > ~/.config/fish/functions/fzf_key_bindings.fish << "EOFZF"
|
cat > ~/.config/fish/functions/fzf_key_bindings.fish << "EOFZF"
|
||||||
function fzf_key_bindings
|
function fzf_key_bindings
|
||||||
function __fzf_select
|
# Due to a bug of fish, we cannot use command substitution,
|
||||||
|
# so we use temporary file instead
|
||||||
|
if [ -z "$TMPDIR" ]
|
||||||
|
set -g TMPDIR /tmp
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fzf_list
|
||||||
command find * -path '*/\.*' -prune \
|
command find * -path '*/\.*' -prune \
|
||||||
-o -type f -print \
|
-o -type f -print \
|
||||||
-o -type d -print \
|
-o -type d -print \
|
||||||
-o -type l -print 2> /dev/null | fzf -m | while read item
|
-o -type l -print 2> /dev/null
|
||||||
echo -n (echo -n "$item" | sed 's/ /\\\\ /g')' '
|
end
|
||||||
|
|
||||||
|
function __fzf_list_dir
|
||||||
|
command find * -path '*/\.*' -prune -o -type d -print 2> /dev/null
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fzf_escape
|
||||||
|
while read item
|
||||||
|
echo -n (echo -n "$item" | sed -E 's/([ "$~'\''([{<>})])/\\\\\\1/g')' '
|
||||||
end
|
end
|
||||||
echo
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_ctrl_t
|
function __fzf_ctrl_t
|
||||||
if [ -n "$TMUX_PANE" -a "$FZF_TMUX" != "0" ]
|
if [ -n "$TMUX_PANE" -a "$FZF_TMUX" != "0" ]
|
||||||
tmux split-window (__fzf_tmux_height) "fish -c 'fzf_key_bindings; __fzf_ctrl_t_tmux \\$TMUX_PANE'"
|
tmux split-window (__fzf_tmux_height) "fish -c 'fzf_key_bindings; __fzf_ctrl_t_tmux \\$TMUX_PANE'"
|
||||||
else
|
else
|
||||||
__fzf_select > $TMPDIR/fzf.result
|
__fzf_list | fzf -m > $TMPDIR/fzf.result
|
||||||
and commandline -i (cat $TMPDIR/fzf.result)
|
and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)
|
||||||
|
commandline -f repaint
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_ctrl_t_tmux
|
function __fzf_ctrl_t_tmux
|
||||||
__fzf_select > $TMPDIR/fzf.result
|
__fzf_list | fzf -m > $TMPDIR/fzf.result
|
||||||
and tmux send-keys -t $argv[1] (cat $TMPDIR/fzf.result)
|
and tmux send-keys -t $argv[1] (cat $TMPDIR/fzf.result | __fzf_escape)
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_ctrl_r
|
function __fzf_ctrl_r
|
||||||
if history | fzf +s +m > $TMPDIR/fzf.result
|
history | fzf +s +m > $TMPDIR/fzf.result
|
||||||
commandline (cat $TMPDIR/fzf.result)
|
and commandline (cat $TMPDIR/fzf.result)
|
||||||
else
|
commandline -f repaint
|
||||||
commandline -f repaint
|
|
||||||
end
|
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_alt_c
|
function __fzf_alt_c
|
||||||
command find * -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m > $TMPDIR/fzf.result
|
# Fish hangs if the command before pipe redirects (2> /dev/null)
|
||||||
if [ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
|
__fzf_list_dir | fzf +m > $TMPDIR/fzf.result
|
||||||
cd (cat $TMPDIR/fzf.result)
|
[ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
|
||||||
end
|
and cd (cat $TMPDIR/fzf.result)
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
end
|
end
|
||||||
@ -339,6 +351,12 @@ done
|
|||||||
if [ $key_bindings -eq 0 -a $has_fish -eq 1 ]; then
|
if [ $key_bindings -eq 0 -a $has_fish -eq 1 ]; then
|
||||||
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
||||||
append_line "fzf_key_bindings" "$bind_file"
|
append_line "fzf_key_bindings" "$bind_file"
|
||||||
|
|
||||||
|
echo ' * Due to a known bug of fish, you may have issues running fzf on fish.'
|
||||||
|
echo ' * If that happens, try the following:'
|
||||||
|
echo ' - Remove ~/.config/fish/functions/fzf.fish'
|
||||||
|
echo ' - Place fzf executable in a directory included in $PATH'
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user