Created
November 20, 2019 08:56
-
-
Save kaimingguo/f56a6977326390a8345fbff299ba5314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add aliases to use git-fzf method | |
alias git-fzf 'set arg1 = `echo \!:1* | awk '"'"'{ print $1 }'"'"'`; \\ | |
bash -c "source ~/.config/bash/plugins/git-fzf.bash && __git_fzf_bash::$arg1" ; \\ | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# usage: | |
# - in bash: ./git-fzf [args] | |
# - add tcsh alias: git-fzf [args] | |
__git_fzf_bash::info() { printf "%b[info]%b %s\n" '\e[0;32m' '\e[0m' "$@" >&2; } | |
__git_fzf_bash::warn() { printf "%b[warn]%b %s\n" '\e[0;33m' '\e[0m' "$@" >&2; } | |
__git_fzf_bash::in_repo() { git rev-parse --is-inside-work-tree >/dev/null; } | |
hash fzf &> /dev/null || { __git_fzf_bash::warn "FZF command required"; exit 2; } | |
git_fzf_pager=$(git config core.pager || echo 'cat') | |
__git_fzf_bash::log() { | |
__git_fzf_bash::in_repo || return 1 | |
local cmd | |
local opts | |
cmd="echo {} | grep -Eo '[a-f0-9]+' | head -1 | xargs -I% git show --color=always % $* | $git_fzf_pager" | |
opts=" | |
$GIT_FZF_DEFAULT_OPTS | |
+s +m --tiebreak=index --preview=\"$cmd\" | |
--bind=\"enter:execute($cmd | LESS='-R' less)\" | |
--bind=\"ctrl-y:execute-silent(echo {} | grep -Eo '[a-f0-9]+' | lead -1 | tr -d '\n' | pbcopy)\" | |
" | |
eval "git log --graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $*" | | |
FZF_DEFAULT_OPTS="$opts" fzf | |
} | |
__git_fzf_bash::diff() { | |
__git_fzf_bash::in_repo || return 1 | |
} | |
__git_fzf_bash::usage() { | |
__git_fzf_bash::in_repo || return 1 | |
} | |
git_fzf() { | |
local args=${1:-} | |
if [[ -z $args ]]; then | |
__git_fzf_bash::usage | |
return | |
fi | |
type __git_fzf_bash::$args &>/dev/null && __git_fzf_bash::$args || __git_fzf_bash::usage | |
} | |
GIT_FZF_DEFAULT_OPTS=" | |
$FZF_DEFAULT_OPS | |
--ansi | |
--height='80%' | |
--preview-window='right:60%' | |
$GIT_FZF_DEFAULT_OPTS | |
" | |
git_fzf "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Idea from: forgit