zsh: cleanup
This commit is contained in:
@@ -94,114 +94,94 @@ export FZF_DEFAULT_OPTS='
|
|||||||
--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'
|
||||||
|
|
||||||
## ripgrep-all
|
|
||||||
# needs https://github.com/phiresky/ripgrep-all
|
|
||||||
rga-fzf() {
|
|
||||||
RG_PREFIX="rga --files-with-matches"
|
|
||||||
local file
|
|
||||||
file="$(
|
|
||||||
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
|
|
||||||
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
|
|
||||||
--phony -q "$1" \
|
|
||||||
--bind "change:reload:$RG_PREFIX {q}" \
|
|
||||||
--preview-window="70%:wrap"
|
|
||||||
)" &&
|
|
||||||
echo "opening $file" &&
|
|
||||||
xdg-open "$file"
|
|
||||||
}
|
|
||||||
zle -N rga-fzf
|
|
||||||
bindkey '^S' "rga-fzf"
|
|
||||||
|
|
||||||
## fzf Bindings in zsh (C-r and C-f)
|
## fzf Bindings in zsh (C-r and C-f)
|
||||||
|
# c/p from ohmyzsh
|
||||||
if [[ -x $(which fzf 2> /dev/null) ]]
|
if [[ -x $(which fzf 2> /dev/null) ]]
|
||||||
then
|
then
|
||||||
# The code at the top and the bottom of this file is the same as in completion.zsh.
|
# some setup
|
||||||
# Refer to that file for explanation.
|
|
||||||
if 'zmodload' 'zsh/parameter' 2>'/dev/null' && (( ${+options} )); then
|
if 'zmodload' 'zsh/parameter' 2>'/dev/null' && (( ${+options} )); then
|
||||||
__fzf_key_bindings_options="options=(${(j: :)${(kv)options[@]}})"
|
__fzf_key_bindings_options="options=(${(j: :)${(kv)options[@]}})"
|
||||||
else
|
else
|
||||||
() {
|
() {
|
||||||
__fzf_key_bindings_options="setopt"
|
__fzf_key_bindings_options="setopt"
|
||||||
'local' '__fzf_opt'
|
'local' '__fzf_opt'
|
||||||
for __fzf_opt in "${(@)${(@f)$(set -o)}%% *}"; do
|
for __fzf_opt in "${(@)${(@f)$(set -o)}%% *}"; do
|
||||||
if [[ -o "$__fzf_opt" ]]; then
|
if [[ -o "$__fzf_opt" ]]; then
|
||||||
__fzf_key_bindings_options+=" -o $__fzf_opt"
|
__fzf_key_bindings_options+=" -o $__fzf_opt"
|
||||||
else
|
else
|
||||||
__fzf_key_bindings_options+=" +o $__fzf_opt"
|
__fzf_key_bindings_options+=" +o $__fzf_opt"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
'emulate' 'zsh' '-o' 'no_aliases'
|
'emulate' 'zsh' '-o' 'no_aliases'
|
||||||
|
|
||||||
{
|
{
|
||||||
|
[[ -o interactive ]] || return 0
|
||||||
|
|
||||||
[[ -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
|
||||||
|
}
|
||||||
|
|
||||||
# CTRL-F - Paste the selected file path(s) into the command line
|
__fzfcmd() {
|
||||||
__fsel() {
|
[ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "$FZF_TMUX_OPTS" ]; } &&
|
||||||
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 \
|
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-70%}} -- " || echo "fzf"
|
||||||
-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() {
|
fzf-file-widget() {
|
||||||
[ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "$FZF_TMUX_OPTS" ]; } &&
|
LBUFFER="${LBUFFER}$(__fsel)"
|
||||||
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-70%}} -- " || echo "fzf"
|
local ret=$?
|
||||||
}
|
zle reset-prompt
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
zle -N fzf-file-widget
|
||||||
|
bindkey '^F' fzf-file-widget
|
||||||
|
|
||||||
fzf-file-widget() {
|
# Ensure precmds are run after cd
|
||||||
LBUFFER="${LBUFFER}$(__fsel)"
|
fzf-redraw-prompt() {
|
||||||
local ret=$?
|
local precmd
|
||||||
zle reset-prompt
|
for precmd in $precmd_functions; do
|
||||||
return $ret
|
$precmd
|
||||||
}
|
done
|
||||||
zle -N fzf-file-widget
|
zle reset-prompt
|
||||||
bindkey '^F' fzf-file-widget
|
}
|
||||||
|
zle -N fzf-redraw-prompt
|
||||||
|
|
||||||
# Ensure precmds are run after cd
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
fzf-redraw-prompt() {
|
fzf-history-widget() {
|
||||||
local precmd
|
local selected num
|
||||||
for precmd in $precmd_functions; do
|
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
|
||||||
$precmd
|
selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' |
|
||||||
done
|
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)) )
|
||||||
zle reset-prompt
|
local ret=$?
|
||||||
}
|
if [ -n "$selected" ]; then
|
||||||
zle -N fzf-redraw-prompt
|
num=$selected[1]
|
||||||
|
if [ -n "$num" ]; then
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
zle vi-fetch-history -n $num
|
||||||
fzf-history-widget() {
|
fi
|
||||||
local selected num
|
fi
|
||||||
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
|
zle reset-prompt
|
||||||
selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' |
|
return $ret
|
||||||
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=$?
|
zle -N fzf-history-widget
|
||||||
if [ -n "$selected" ]; then
|
bindkey '^R' fzf-history-widget
|
||||||
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 {
|
} always {
|
||||||
eval $__fzf_key_bindings_options
|
eval $__fzf_key_bindings_options
|
||||||
'unset' '__fzf_key_bindings_options'
|
'unset' '__fzf_key_bindings_options'
|
||||||
}
|
}
|
||||||
else
|
else # fzf is not installed
|
||||||
bindkey '^R' history-incremental-search-backward
|
bindkey '^R' history-incremental-search-backward
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user