mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-06-02 15:30:50 +00:00
Fish shell support - installer / key bindings (#33)
This commit is contained in:
parent
89eb1575e7
commit
7d15071c63
35
README.md
35
README.md
|
@ -35,13 +35,13 @@ curl -L https://github.com/junegunn/fzf/archive/master.tar.gz |
|
||||||
|
|
||||||
The script will setup:
|
The script will setup:
|
||||||
|
|
||||||
- `fzf` executable
|
- `fzf` function (bash, zsh, fish)
|
||||||
- Key bindings (`CTRL-T`, `CTRL-R`, and `ALT-C`) for bash and zsh
|
- Key bindings (`CTRL-T`, `CTRL-R`, and `ALT-C`) (bash, zsh, fish)
|
||||||
- Fuzzy auto-completion for bash
|
- Fuzzy auto-completion (bash)
|
||||||
|
|
||||||
If you don't use bash or zsh, you have to manually place fzf executable in a
|
If you don't use any of the aforementioned shells, you have to manually place
|
||||||
directory included in `$PATH`. Key bindings and auto-completion will not be
|
fzf executable in a directory included in `$PATH`. Key bindings and
|
||||||
available in that case.
|
auto-completion will not be available in that case.
|
||||||
|
|
||||||
### Install as Vim plugin
|
### Install as Vim plugin
|
||||||
|
|
||||||
|
@ -458,6 +458,29 @@ export FZF_DEFAULT_COMMAND='ag -l -g ""'
|
||||||
fzf
|
fzf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Fish shell
|
||||||
|
|
||||||
|
It's [a known bug of fish](https://github.com/fish-shell/fish-shell/issues/1362)
|
||||||
|
that it doesn't allow reading from STDIN in command substitution, which means
|
||||||
|
simple `vim (fzf)` won't work as expected. The workaround is to store the result
|
||||||
|
of fzf to a temporary file.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
function vimf
|
||||||
|
if fzf > $TMPDIR/fzf.result
|
||||||
|
vim (cat $TMPDIR/fzf.result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function fe
|
||||||
|
set tmp $TMPDIR/fzf.result
|
||||||
|
fzf --query="$argv[1]" --select-1 --exit-0 > $tmp
|
||||||
|
if [ (cat $tmp | wc -l) -gt 0 ]
|
||||||
|
vim (cat $tmp)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
fzf works on [Cygwin](http://www.cygwin.com/) and
|
fzf works on [Cygwin](http://www.cygwin.com/) and
|
||||||
|
|
109
install
109
install
|
@ -230,29 +230,118 @@ EOFZF
|
||||||
echo "OK"
|
echo "OK"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo
|
# fish
|
||||||
for shell in bash zsh; do
|
has_fish=0
|
||||||
rc=~/.${shell}rc
|
if [ -n "$(which fish)" ]; then
|
||||||
src="source ~/.fzf.${shell}"
|
has_fish=1
|
||||||
|
echo -n "Generate ~/.config/fish/functions/fzf.fish ... "
|
||||||
|
mkdir -p ~/.config/fish/functions
|
||||||
|
cat > ~/.config/fish/functions/fzf.fish << EOFZF
|
||||||
|
function fzf
|
||||||
|
$fzf_cmd \$argv
|
||||||
|
end
|
||||||
|
EOFZF
|
||||||
|
echo "ok"
|
||||||
|
|
||||||
echo "Update $rc:"
|
if [ $key_bindings -eq 0 ]; then
|
||||||
echo " - $src"
|
echo -n "Generate ~/.config/fish/functions/fzf_key_bindings.fish ... "
|
||||||
line=$(grep -nF "$src" $rc | sed 's/:.*//')
|
cat > ~/.config/fish/functions/fzf_key_bindings.fish << "EOFZF"
|
||||||
|
function fzf_key_bindings
|
||||||
|
function __fzf_select
|
||||||
|
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')' '
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fzf_ctrl_t_tmux
|
||||||
|
__fzf_select > $TMPDIR/fzf.result
|
||||||
|
and tmux send-keys -t $argv[1] (cat $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
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fzf_alt_c
|
||||||
|
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
|
||||||
|
commandline -f repaint
|
||||||
|
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
|
||||||
|
EOFZF
|
||||||
|
echo "ok"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
append_line() {
|
||||||
|
echo "Update $2:"
|
||||||
|
echo " - $1"
|
||||||
|
[ -f "$2" ] || touch "$2"
|
||||||
|
line=$(grep -nF "$1" "$2" | sed 's/:.*//')
|
||||||
if [ -n "$line" ]; then
|
if [ -n "$line" ]; then
|
||||||
echo " - Already exists (line #$line)"
|
echo " - Already exists (line #$line)"
|
||||||
else
|
else
|
||||||
echo $src >> $rc
|
echo "$1" >> "$2"
|
||||||
echo " - Added"
|
echo " - Added"
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
for shell in bash zsh; do
|
||||||
|
append_line "source ~/.fzf.${shell}" ~/.${shell}rc
|
||||||
done
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Finished. Reload your .bashrc or .zshrc.
|
Finished. Restart your shell or reload config file.
|
||||||
source ~/.bashrc # bash
|
source ~/.bashrc # bash
|
||||||
source ~/.zshrc # zsh
|
source ~/.zshrc # zsh
|
||||||
|
EOF
|
||||||
|
[ $has_fish -eq 1 ] && echo " fzf_key_bindings # fish"; cat << EOF
|
||||||
|
|
||||||
To uninstall fzf, simply remove the added line.
|
To uninstall fzf, simply remove the added lines.
|
||||||
|
|
||||||
For more information, see: https://github.com/junegunn/fzf
|
For more information, see: https://github.com/junegunn/fzf
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Reference in New Issue
Block a user