|
|
@ -73,27 +73,80 @@ if [ $commands[fzf] ]; then
|
|
|
|
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
|
|
|
|
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# CTRL-G
|
|
|
|
# https://junegunn.kr/2016/07/fzf-git/
|
|
|
|
__fgit() {
|
|
|
|
is_in_git_repo() {
|
|
|
|
local cmd="git status --porcelain | awk '{ print \$2 }'"
|
|
|
|
git rev-parse HEAD > /dev/null 2>&1
|
|
|
|
setopt localoptions pipefail no_aliases 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fzf-down() {
|
|
|
|
|
|
|
|
fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gf() {
|
|
|
|
|
|
|
|
is_in_git_repo || return
|
|
|
|
|
|
|
|
git -c color.status=always status --short |
|
|
|
|
|
|
|
|
fzf-down -m --ansi --nth 2..,.. \
|
|
|
|
|
|
|
|
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' |
|
|
|
|
|
|
|
|
cut -c4- | sed 's/.* -> //'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gb() {
|
|
|
|
|
|
|
|
is_in_git_repo || return
|
|
|
|
|
|
|
|
git branch -a --color=always | grep -v '/HEAD\s' | sort |
|
|
|
|
|
|
|
|
fzf-down --ansi --multi --tac --preview-window right:70% \
|
|
|
|
|
|
|
|
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' |
|
|
|
|
|
|
|
|
sed 's/^..//' | cut -d' ' -f1 |
|
|
|
|
|
|
|
|
sed 's#^remotes/##'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gt() {
|
|
|
|
|
|
|
|
is_in_git_repo || return
|
|
|
|
|
|
|
|
git tag --sort -version:refname |
|
|
|
|
|
|
|
|
fzf-down --multi --preview-window right:70% \
|
|
|
|
|
|
|
|
--preview 'git show --color=always {}'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gh() {
|
|
|
|
|
|
|
|
is_in_git_repo || return
|
|
|
|
|
|
|
|
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
|
|
|
|
|
|
|
|
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
|
|
|
|
|
|
|
|
--header 'Press CTRL-S to toggle sort' \
|
|
|
|
|
|
|
|
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' |
|
|
|
|
|
|
|
|
grep -o "[a-f0-9]\{7,\}"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gr() {
|
|
|
|
|
|
|
|
is_in_git_repo || return
|
|
|
|
|
|
|
|
git remote -v | awk '{print $1 "\t" $2}' | uniq |
|
|
|
|
|
|
|
|
fzf-down --tac \
|
|
|
|
|
|
|
|
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' |
|
|
|
|
|
|
|
|
cut -d$'\t' -f1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gs() {
|
|
|
|
|
|
|
|
is_in_git_repo || return
|
|
|
|
|
|
|
|
git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' |
|
|
|
|
|
|
|
|
cut -d: -f1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
join-lines() {
|
|
|
|
local item
|
|
|
|
local item
|
|
|
|
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS" $(__fzfcmd) -m "$@" | while read item; do
|
|
|
|
while read item; do
|
|
|
|
echo -n "${(q)item} "
|
|
|
|
echo -n "${(q)item} "
|
|
|
|
done
|
|
|
|
done
|
|
|
|
local ret=$?
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
return $ret
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fzf-git-widget() {
|
|
|
|
bind-git-helper() {
|
|
|
|
LBUFFER="${LBUFFER}$(__fgit)"
|
|
|
|
local c
|
|
|
|
local ret=$?
|
|
|
|
for c in $@; do
|
|
|
|
zle reset-prompt
|
|
|
|
eval "fzf-g$c-widget() { local result=\$(_g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }"
|
|
|
|
return $ret
|
|
|
|
eval "zle -N fzf-g$c-widget"
|
|
|
|
|
|
|
|
eval "bindkey '^g$c' fzf-g$c-widget" # So it works in tmux
|
|
|
|
|
|
|
|
eval "bindkey '^g^$c' fzf-g$c-widget"
|
|
|
|
|
|
|
|
done
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zle -N fzf-git-widget
|
|
|
|
bind-git-helper f b t r h s
|
|
|
|
bindkey '^G' fzf-git-widget
|
|
|
|
unset -f bind-git-helper
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ $commands[exa] ]; then
|
|
|
|
if [ $commands[exa] ]; then
|
|
|
|