mirror of https://github.com/junegunn/fzf
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-tmuxpull/145/head
parent
dd6138a655
commit
3935aa84d8
@ -1,9 +0,0 @@
|
|||||||
#!/bin/zsh
|
|
||||||
# ____ ____
|
|
||||||
# / __/___ / __/
|
|
||||||
# / /_/_ / / /_
|
|
||||||
# / __/ / /_/ __/
|
|
||||||
# /_/ /___/_/-completion.zsh
|
|
||||||
#
|
|
||||||
|
|
||||||
# TODO
|
|
@ -0,0 +1,75 @@
|
|||||||
|
# Key bindings
|
||||||
|
# ------------
|
||||||
|
__fsel() {
|
||||||
|
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- | fzf -m | while read item; do
|
||||||
|
printf '%q ' "$item"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $- =~ i ]]; then
|
||||||
|
|
||||||
|
__fsel_tmux() {
|
||||||
|
local height
|
||||||
|
height=${FZF_TMUX_HEIGHT:-40%}
|
||||||
|
if [[ $height =~ %$ ]]; then
|
||||||
|
height="-p ${height%\%}"
|
||||||
|
else
|
||||||
|
height="-l $height"
|
||||||
|
fi
|
||||||
|
tmux split-window $height "bash -c 'source ~/.fzf.bash; tmux send-keys -t $TMUX_PANE \"\$(__fsel)\"'"
|
||||||
|
}
|
||||||
|
|
||||||
|
__fcd() {
|
||||||
|
local dir
|
||||||
|
dir=$(command find -L ${1:-.} \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
||||||
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m) && printf 'cd %q' "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
__use_tmux=0
|
||||||
|
[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=1
|
||||||
|
|
||||||
|
if [ -z "$(set -o | \grep '^vi.*on')" ]; then
|
||||||
|
# Required to refresh the prompt after fzf
|
||||||
|
bind '"\er": redraw-current-line'
|
||||||
|
|
||||||
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
|
if [ $__use_tmux -eq 1 ]; then
|
||||||
|
bind '"\C-t": " \C-u \C-a\C-k$(__fsel_tmux)\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'
|
||||||
|
else
|
||||||
|
bind '"\C-t": " \C-u \C-a\C-k$(__fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
|
bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s --tac +m -n2..,.. | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
||||||
|
|
||||||
|
# ALT-C - cd into the selected directory
|
||||||
|
bind '"\ec": " \C-e\C-u$(__fcd)\e\C-e\er\C-m"'
|
||||||
|
else
|
||||||
|
bind '"\C-x\C-e": shell-expand-line'
|
||||||
|
bind '"\C-x\C-r": redraw-current-line'
|
||||||
|
|
||||||
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
|
# - FIXME: Selected items are attached to the end regardless of cursor position
|
||||||
|
if [ $__use_tmux -eq 1 ]; then
|
||||||
|
bind '"\C-t": "\e$a \eddi$(__fsel_tmux)\C-x\C-e\e0P$xa"'
|
||||||
|
else
|
||||||
|
bind '"\C-t": "\e$a \eddi$(__fsel)\C-x\C-e\e0Px$a \C-x\C-r\exa "'
|
||||||
|
fi
|
||||||
|
bind -m vi-command '"\C-t": "i\C-t"'
|
||||||
|
|
||||||
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
|
bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s --tac +m -n2..,.. | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"'
|
||||||
|
bind -m vi-command '"\C-r": "i\C-r"'
|
||||||
|
|
||||||
|
# ALT-C - cd into the selected directory
|
||||||
|
bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"'
|
||||||
|
bind -m vi-command '"\ec": "i\ec"'
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset __use_tmux
|
||||||
|
|
||||||
|
fi
|
@ -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
|
||||||
|
|
@ -0,0 +1,59 @@
|
|||||||
|
# Key bindings
|
||||||
|
# ------------
|
||||||
|
# CTRL-T - Paste the selected file path(s) into the command line
|
||||||
|
__fsel() {
|
||||||
|
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- | fzf -m | while read item; do
|
||||||
|
printf '%q ' "$item"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $- =~ i ]]; then
|
||||||
|
|
||||||
|
if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then
|
||||||
|
fzf-file-widget() {
|
||||||
|
local height
|
||||||
|
height=${FZF_TMUX_HEIGHT:-40%}
|
||||||
|
if [[ $height =~ %$ ]]; then
|
||||||
|
height="-p ${height%\%}"
|
||||||
|
else
|
||||||
|
height="-l $height"
|
||||||
|
fi
|
||||||
|
tmux split-window $height "zsh -c 'source ~/.fzf.zsh; tmux send-keys -t $TMUX_PANE \"\$(__fsel)\"'"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fzf-file-widget() {
|
||||||
|
LBUFFER="${LBUFFER}$(__fsel)"
|
||||||
|
zle redisplay
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
zle -N fzf-file-widget
|
||||||
|
bindkey '^T' fzf-file-widget
|
||||||
|
|
||||||
|
# ALT-C - cd into the selected directory
|
||||||
|
fzf-cd-widget() {
|
||||||
|
cd "${$(command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
||||||
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m):-.}"
|
||||||
|
zle reset-prompt
|
||||||
|
}
|
||||||
|
zle -N fzf-cd-widget
|
||||||
|
bindkey '\ec' fzf-cd-widget
|
||||||
|
|
||||||
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
|
fzf-history-widget() {
|
||||||
|
local selected
|
||||||
|
if selected=$(fc -l 1 | fzf +s --tac +m -n2..,.. -q "$LBUFFER"); then
|
||||||
|
num=$(echo "$selected" | head -1 | awk '{print $1}' | sed 's/[^0-9]//g')
|
||||||
|
LBUFFER=!$num
|
||||||
|
zle expand-history
|
||||||
|
fi
|
||||||
|
zle redisplay
|
||||||
|
}
|
||||||
|
zle -N fzf-history-widget
|
||||||
|
bindkey '^R' fzf-history-widget
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue