Naming refactor

Former-commit-id: 2499abae84
This commit is contained in:
Wenxuan 2018-04-30 11:02:16 +08:00
parent e7817188aa
commit 1de566046b

View file

@ -17,8 +17,8 @@ forgit::fzf() {
}
# diff is fancy with diff-so-fancy!
(( $+commands[diff-so-fancy] )) && fancy='|diff-so-fancy'
(( $+commands[emojify] )) && emojify='|emojify'
(( $+commands[diff-so-fancy] )) && forgit_fancy='|diff-so-fancy'
(( $+commands[emojify] )) && forgit_emojify='|emojify'
forgit::inside_work_tree() {
git rev-parse --is-inside-work-tree >/dev/null
@ -27,8 +27,8 @@ forgit::inside_work_tree() {
# git commit browser
forgit::log() {
forgit::inside_work_tree || return 1
local cmd="echo {} |grep -o '[a-f0-9]\{7\}' |head -1 |xargs -I% git show --color=always % $emojify $fancy"
eval "git log --graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $@ $emojify" |
local cmd="echo {} |grep -o '[a-f0-9]\{7\}' |head -1 |xargs -I% git show --color=always % $forgit_emojify $forgit_fancy"
eval "git log --graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $@ $forgit_emojify" |
forgit::fzf -e +s --tiebreak=index \
--bind="enter:execute($cmd |LESS='-R' less)" \
--preview="$cmd"
@ -37,7 +37,7 @@ forgit::log() {
# git diff brower
forgit::diff() {
forgit::inside_work_tree || return 1
local cmd="git diff --color=always -- {} $emojify $fancy"
local cmd="git diff --color=always -- {} $forgit_emojify $forgit_fancy"
git ls-files --modified $(git rev-parse --show-toplevel)|
forgit::fzf -e -0 \
--bind="enter:execute($cmd |LESS='-R' less)" \
@ -52,20 +52,20 @@ forgit::add() {
grep 31m |
awk '{printf "[%10s] ", $1; $1=""; print $0}' |
forgit::fzf -e -0 -m --nth 2..,.. \
--preview="git diff --color=always -- {-1} $emojify $fancy" |
--preview="git diff --color=always -- {-1} $forgit_emojify $forgit_fancy" |
cut -d] -f2 |
sed 's/.* -> //') # for rename case
[[ -n $files ]] && echo $files |xargs -I{} git add {} && git status
}
# git ignore generator
export giCache=~/.giCache
export giIndex=$giCache/.list
export FORGIT_GI_CACHE=~/.gicache
export FORGIT_GI_INDEX=$FORGIT_GI_CACHE/.index
forgit:ignore() {
[ -f $giIndex ] || forgit::ignore::update
local preview="echo {} |awk '{print \$2}' |xargs -I% bash -c 'cat $giCache/% 2>/dev/null || (curl -sL https://www.gitignore.io/api/% |tee $giCache/%)'"
[ -f $FORGIT_GI_INDEX ] || forgit::ignore::update
local preview="echo {} |awk '{print \$2}' |xargs -I% bash -c 'cat $FORGIT_GI_CACHE/% 2>/dev/null || (curl -sL https://www.gitignore.io/api/% |tee $FORGIT_GI_CACHE/%)'"
IFS=$'\n'
[[ $# -gt 0 ]] && args=($@) || args=($(cat $giIndex |nl -nrn -w4 -s' ' |fzf -m --preview="$preview" --preview-window="right:70%" |awk '{print $2}'))
[[ $# -gt 0 ]] && args=($@) || args=($(cat $FORGIT_GI_INDEX |nl -nrn -w4 -s' ' |fzf -m --preview="$preview" --preview-window="right:70%" |awk '{print $2}'))
test -z "$args" && return 1
local options=(
'(1) Output to stdout'
@ -85,16 +85,16 @@ forgit:ignore() {
esac
}
forgit::ignore::update() {
mkdir -p $giCache
curl -sL https://www.gitignore.io/api/list |tr ',' '\n' > $giIndex
mkdir -p $FORGIT_GI_CACHE
curl -sL https://www.gitignore.io/api/list |tr ',' '\n' > $FORGIT_GI_INDEX
}
forgit::ignore::get() {
mkdir -p $giCache
echo $@ |xargs -I{} bash -c "cat $giCache/{} 2>/dev/null || (curl -sL https://www.gitignore.io/api/{} |tee $giCache/{})"
mkdir -p $FORGIT_GI_CACHE
echo $@ |xargs -I{} bash -c "cat $FORGIT_GI_CACHE/{} 2>/dev/null || (curl -sL https://www.gitignore.io/api/{} |tee $FORGIT_GI_CACHE/{})"
}
forgit::ignore::clean() {
setopt localoptions rmstarsilent
[[ -d $giCache ]] && rm -rf $giCache/*
[[ -d $FORGIT_GI_CACHE ]] && rm -rf $FORGIT_GI_CACHE/*
}
# add aliases