summaryrefslogtreecommitdiff
path: root/shell/key-bindings.fish
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-03-13 13:08:42 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-03-13 17:41:00 +0900
commit3935aa84d8cc66c0371926c61afe89832f00df10 (patch)
tree1c5ae8f1cdf7f6cf850ae296e12b10c1bef9de2e /shell/key-bindings.fish
parentdd6138a6559363871d88c594ab9d170e36959129 (diff)
downloadfzf-3935aa84d8cc66c0371926c61afe89832f00df10.tar.gz
Refactor shell extensions
- Use symlinks instead of generating the full content - Update fish_user_paths and remove ~/.config/fish/functions/fzf.fish - Create wrapper script for fzf when Ruby version and use it instead of exported function not to break fzf-tmux
Diffstat (limited to 'shell/key-bindings.fish')
-rw-r--r--shell/key-bindings.fish79
1 files changed, 79 insertions, 0 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
new file mode 100644
index 00000000..be39e3d5
--- /dev/null
+++ b/shell/key-bindings.fish
@@ -0,0 +1,79 @@
+# Key bindings
+# ------------
+function fzf_key_bindings
+ # 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 -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-
+ end
+
+ function __fzf_list_dir
+ command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) \
+ -prune -o -type d -print 2> /dev/null | sed 1d | cut -b3-
+ end
+
+ function __fzf_escape
+ while read item
+ echo -n (echo -n "$item" | sed -E 's/([ "$~'\''([{<>})])/\\\\\\1/g')' '
+ end
+ 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_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_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
+ 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
+ # 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
+
+ function __fzf_tmux_height
+ if set -q FZF_TMUX_HEIGHT
+ set height $FZF_TMUX_HEIGHT
+ else
+ set height 40%
+ end
+ if echo $height | \grep -q -E '%$'
+ echo "-p "(echo $height | sed 's/%$//')
+ else
+ echo "-l $height"
+ end
+ set -e height
+ end
+
+ bind \ct '__fzf_ctrl_t'
+ bind \cr '__fzf_ctrl_r'
+ bind \ec '__fzf_alt_c'
+end
+