summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2014-07-06 03:31:32 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2014-07-06 20:51:51 +0900
commitdaf08f801f461c47fbc34394939ddadb14e90446 (patch)
tree9f7d29da42974efa2bb7852fbd84544ce15394e9
parent4e2a1fe5c8cbbbb73316b67b309c01e99bd673ba (diff)
[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
-rwxr-xr-xinstall52
1 files changed, 35 insertions, 17 deletions
diff --git a/install b/install
index 46362ab3..bc1fbbb3 100755
--- a/install
+++ b/install
@@ -250,46 +250,58 @@ EOFZF
echo -n "Generate ~/.config/fish/functions/fzf_key_bindings.fish ... "
cat > ~/.config/fish/functions/fzf_key_bindings.fish << "EOFZF"
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 \
-o -type f -print \
-o -type d -print \
- -o -type l -print 2> /dev/null | fzf -m | while read item
- echo -n (echo -n "$item" | sed 's/ /\\\\ /g')' '
+ -o -type l -print 2> /dev/null
+ 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
- echo
end
function __fzf_ctrl_t
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'"
else
- __fzf_select > $TMPDIR/fzf.result
- and commandline -i (cat $TMPDIR/fzf.result)
+ __fzf_list | fzf -m > $TMPDIR/fzf.result
+ and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)
+ commandline -f repaint
rm -f $TMPDIR/fzf.result
end
end
function __fzf_ctrl_t_tmux
- __fzf_select > $TMPDIR/fzf.result
- and tmux send-keys -t $argv[1] (cat $TMPDIR/fzf.result)
+ __fzf_list | fzf -m > $TMPDIR/fzf.result
+ and tmux send-keys -t $argv[1] (cat $TMPDIR/fzf.result | __fzf_escape)
rm -f $TMPDIR/fzf.result
end
function __fzf_ctrl_r
- if history | fzf +s +m > $TMPDIR/fzf.result
- commandline (cat $TMPDIR/fzf.result)
- else
- commandline -f repaint
- end
+ history | fzf +s +m > $TMPDIR/fzf.result
+ and commandline (cat $TMPDIR/fzf.result)
+ commandline -f repaint
rm -f $TMPDIR/fzf.result
end
function __fzf_alt_c
- command find * -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m > $TMPDIR/fzf.result
- if [ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
- cd (cat $TMPDIR/fzf.result)
- end
+ # Fish hangs if the command before pipe redirects (2> /dev/null)
+ __fzf_list_dir | fzf +m > $TMPDIR/fzf.result
+ [ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
+ and cd (cat $TMPDIR/fzf.result)
commandline -f repaint
rm -f $TMPDIR/fzf.result
end
@@ -339,6 +351,12 @@ done
if [ $key_bindings -eq 0 -a $has_fish -eq 1 ]; then
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
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
cat << EOF