fzf additions

- `z` for fasd support
- `CTRL-G` for git changed files
Alpha Chen 4 years ago
parent c5cbda47f8
commit f7a53d3c56
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -43,10 +43,39 @@ if [ -e /usr/local/opt/fzf/shell/completion.zsh ]; then
fi fi
if [ $commands[fzf] ]; then if [ $commands[fzf] ]; then
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_DEFAULT_COMMAND="rg --files" export FZF_DEFAULT_COMMAND="rg --files"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="find . -type d" export FZF_ALT_C_COMMAND="find . -type d"
alias fzf=fzf-tmux # alias fzf=fzf-tmux
z() {
[ $# -gt 0 ] && fasd_cd -d "$*" && return
local dir
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
}
# CTRL-G
__fgit() {
local cmd="git status --porcelain | awk '{ print \$2 }'"
setopt localoptions pipefail no_aliases 2> /dev/null
local item
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS" $(__fzfcmd) -m "$@" | while read item; do
echo -n "${(q)item} "
done
local ret=$?
echo
return $ret
}
fzf-git-widget() {
LBUFFER="${LBUFFER}$(__fgit)"
local ret=$?
zle reset-prompt
return $ret
}
zle -N fzf-git-widget
bindkey '^G' fzf-git-widget
fi fi
[[ -s "$HOME/.zshrc.local" ]] && . "$HOME/.zshrc.local" [[ -s "$HOME/.zshrc.local" ]] && . "$HOME/.zshrc.local"

Loading…
Cancel
Save