shell: integrate fzf better
This commit is contained in:
@@ -39,6 +39,22 @@ __prompt_command() {
|
|||||||
# ============================== vi-Mode
|
# ============================== vi-Mode
|
||||||
set -o vi
|
set -o vi
|
||||||
|
|
||||||
|
# ============================== fzf
|
||||||
|
export FZF_DEFAULT_OPTS='
|
||||||
|
--layout=reverse
|
||||||
|
--color=fg:#5c6a72,bg:#FDF6E3,hl:#8da101
|
||||||
|
--color=fg+:#5c6a72,bg+:#eee8d5,hl+:#8da101
|
||||||
|
--color=info:#5c6a72,prompt:#5c6a72,pointer:#5c6a72
|
||||||
|
--color=marker:#5c6a72,spinner:#5c6a72,header:#5c6a72'
|
||||||
|
|
||||||
|
if [[ -d ~/.vim/plugged/fzf ]]; then
|
||||||
|
source ~/.vim/plugged/fzf/shell/completion.bash
|
||||||
|
source ~/.vim/plugged/fzf/shell/key-bindings.bash
|
||||||
|
bind '"":"fzf-file-widget\n"'
|
||||||
|
else
|
||||||
|
bindkey '^R' history-incremental-search-backward
|
||||||
|
fi
|
||||||
|
|
||||||
# ============================== Source other definitions
|
# ============================== Source other definitions
|
||||||
[ -f ~/.shellrc.local ] && source ~/.shellrc.local
|
[ -f ~/.shellrc.local ] && source ~/.shellrc.local
|
||||||
[ -f ~/.shellrc.alias ] && source ~/.shellrc.alias
|
[ -f ~/.shellrc.alias ] && source ~/.shellrc.alias
|
||||||
|
|||||||
@@ -84,105 +84,20 @@ RPS2=$RPS1
|
|||||||
bindkey -v '^?' backward-delete-char
|
bindkey -v '^?' backward-delete-char
|
||||||
|
|
||||||
# ============================== fzf
|
# ============================== fzf
|
||||||
export FZF_DEFAULT_COMMAND='find .'
|
# export FZF_DEFAULT_COMMAND='fd .'
|
||||||
export FZF_DEFAULT_OPTS='
|
export FZF_DEFAULT_OPTS='
|
||||||
--layout=reverse
|
--layout=reverse
|
||||||
--bind=tab:down
|
|
||||||
--bind=btab:up
|
|
||||||
--color=fg:#5c6a72,bg:#FDF6E3,hl:#8da101
|
--color=fg:#5c6a72,bg:#FDF6E3,hl:#8da101
|
||||||
--color=fg+:#5c6a72,bg+:#eee8d5,hl+:#8da101
|
--color=fg+:#5c6a72,bg+:#eee8d5,hl+:#8da101
|
||||||
--color=info:#5c6a72,prompt:#5c6a72,pointer:#5c6a72
|
--color=info:#5c6a72,prompt:#5c6a72,pointer:#5c6a72
|
||||||
--color=marker:#5c6a72,spinner:#5c6a72,header:#5c6a72'
|
--color=marker:#5c6a72,spinner:#5c6a72,header:#5c6a72'
|
||||||
|
|
||||||
## fzf Bindings in zsh (C-r and C-f)
|
if [[ -d ~/.vim/plugged/fzf ]]; then
|
||||||
# c/p from ohmyzsh
|
source ~/.vim/plugged/fzf/shell/completion.zsh
|
||||||
if [[ -x $(which fzf 2> /dev/null) ]]
|
source ~/.vim/plugged/fzf/shell/key-bindings.zsh
|
||||||
then
|
bindkey '^F' fzf-file-widget
|
||||||
# some setup
|
else
|
||||||
if 'zmodload' 'zsh/parameter' 2>'/dev/null' && (( ${+options} )); then
|
bindkey '^R' history-incremental-search-backward
|
||||||
__fzf_key_bindings_options="options=(${(j: :)${(kv)options[@]}})"
|
|
||||||
else
|
|
||||||
() {
|
|
||||||
__fzf_key_bindings_options="setopt"
|
|
||||||
'local' '__fzf_opt'
|
|
||||||
for __fzf_opt in "${(@)${(@f)$(set -o)}%% *}"; do
|
|
||||||
if [[ -o "$__fzf_opt" ]]; then
|
|
||||||
__fzf_key_bindings_options+=" -o $__fzf_opt"
|
|
||||||
else
|
|
||||||
__fzf_key_bindings_options+=" +o $__fzf_opt"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
'emulate' 'zsh' '-o' 'no_aliases'
|
|
||||||
|
|
||||||
{
|
|
||||||
[[ -o interactive ]] || return 0
|
|
||||||
|
|
||||||
# CTRL-F - Paste the selected file path(s) into the command line
|
|
||||||
__fsel() {
|
|
||||||
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
|
||||||
-o -type f -print \
|
|
||||||
-o -type d -print \
|
|
||||||
-o -type l -print 2> /dev/null | cut -b3-"}"
|
|
||||||
setopt localoptions pipefail no_aliases 2> /dev/null
|
|
||||||
eval "$cmd" | FZF_DEFAULT_OPTS="--preview='cat {}' --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do
|
|
||||||
echo -n "${(q)item} "
|
|
||||||
done
|
|
||||||
local ret=$?
|
|
||||||
echo
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
__fzfcmd() {
|
|
||||||
[ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "$FZF_TMUX_OPTS" ]; } &&
|
|
||||||
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-70%}} -- " || echo "fzf"
|
|
||||||
}
|
|
||||||
|
|
||||||
fzf-file-widget() {
|
|
||||||
LBUFFER="${LBUFFER}$(__fsel)"
|
|
||||||
local ret=$?
|
|
||||||
zle reset-prompt
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
zle -N fzf-file-widget
|
|
||||||
bindkey '^F' fzf-file-widget
|
|
||||||
|
|
||||||
# Ensure precmds are run after cd
|
|
||||||
fzf-redraw-prompt() {
|
|
||||||
local precmd
|
|
||||||
for precmd in $precmd_functions; do
|
|
||||||
$precmd
|
|
||||||
done
|
|
||||||
zle reset-prompt
|
|
||||||
}
|
|
||||||
zle -N fzf-redraw-prompt
|
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
|
||||||
fzf-history-widget() {
|
|
||||||
local selected num
|
|
||||||
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
|
|
||||||
selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' |
|
|
||||||
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-30%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
|
|
||||||
local ret=$?
|
|
||||||
if [ -n "$selected" ]; then
|
|
||||||
num=$selected[1]
|
|
||||||
if [ -n "$num" ]; then
|
|
||||||
zle vi-fetch-history -n $num
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
zle reset-prompt
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
zle -N fzf-history-widget
|
|
||||||
bindkey '^R' fzf-history-widget
|
|
||||||
|
|
||||||
} always {
|
|
||||||
eval $__fzf_key_bindings_options
|
|
||||||
'unset' '__fzf_key_bindings_options'
|
|
||||||
}
|
|
||||||
else # fzf is not installed
|
|
||||||
bindkey '^R' history-incremental-search-backward
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ============================== Fancy Hacks
|
# ============================== Fancy Hacks
|
||||||
|
|||||||
Reference in New Issue
Block a user