178 lines
4.4 KiB
Bash
Executable File
178 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -u
|
|
|
|
ORIGIN=origin
|
|
UPSTREAM=$ORIGIN
|
|
MASTER=$UPSTREAM/master
|
|
DEBUG=${DEBUG:- 0}
|
|
|
|
if [[ $# -gt 0 && "$1" == "-dry" ]]; then
|
|
DRY=true
|
|
else
|
|
DRY=false
|
|
fi
|
|
|
|
function log() {
|
|
if (( $DEBUG )); then
|
|
echo "$*"
|
|
fi
|
|
}
|
|
|
|
function run() {
|
|
log "$*"
|
|
if [[ $DRY != "true" ]]; then
|
|
"$@"
|
|
fi
|
|
}
|
|
|
|
function git_alias() {
|
|
local name="$1"
|
|
local value="$2"
|
|
git_set "alias.$name" "$value"
|
|
}
|
|
|
|
function git_unalias() {
|
|
local name="$1"
|
|
git_unset "alias.$name"
|
|
}
|
|
|
|
function git_set() {
|
|
local name="$1"
|
|
local value="$2"
|
|
run git config --global --replace-all "$name" "$value"
|
|
}
|
|
|
|
function git_unset() {
|
|
local name="$1"
|
|
run git config --global --unset "$name"
|
|
}
|
|
|
|
function can_run() {
|
|
local application="$1"
|
|
command -v "$application" > /dev/null
|
|
}
|
|
|
|
function activate_delta() {
|
|
git_set core.pager delta
|
|
git_set interactive.diffFilter "delta --color-only"
|
|
git_set delta.navigate true
|
|
git_set delta.side-by-side false
|
|
git_set merge.conflictstyle diff3
|
|
git_set diff.colorMoved default
|
|
}
|
|
|
|
function deactivate_delta() {
|
|
git_unset core.pager
|
|
git_unset interactive.diffFilter
|
|
git_unset delta.navigate
|
|
git_unset delta.side-by-side
|
|
}
|
|
|
|
function activate_diff_so_fancy() {
|
|
git_set core.pager "diff-so-fancy | less --tabs=4 -RFX"
|
|
git_set interactive.diffFilter "diff-so-fancy --patch"
|
|
}
|
|
|
|
function set_colors() {
|
|
git_set color.ui true
|
|
|
|
git_set color.diff-highlight.oldNormal "red bold"
|
|
git_set color.diff-highlight.oldHighlight "red bold 52"
|
|
git_set color.diff-highlight.newNormal "green bold"
|
|
git_set color.diff-highlight.newHighlight "green bold 22"
|
|
|
|
git_set color.diff.meta "11"
|
|
git_set color.diff.frag "magenta bold"
|
|
git_set color.diff.func "146 bold"
|
|
git_set color.diff.commit "yellow bold"
|
|
git_set color.diff.old "red bold"
|
|
git_set color.diff.new "green bold"
|
|
git_set color.diff.whitespace "red reverse"
|
|
}
|
|
|
|
function unset_colors() {
|
|
git_unset color.diff-highlight.oldNormal
|
|
git_unset color.diff-highlight.oldHighlight
|
|
git_unset color.diff-highlight.newNormal
|
|
git_unset color.diff-highlight.newHighlight
|
|
|
|
git_unset color.diff.meta
|
|
git_unset color.diff.frag
|
|
git_unset color.diff.func
|
|
git_unset color.diff.commit
|
|
git_unset color.diff.old
|
|
git_unset color.diff.new
|
|
git_unset color.diff.whitespace
|
|
}
|
|
|
|
git_set core.editor vim
|
|
|
|
git_alias st status
|
|
|
|
git_alias br branch
|
|
git_alias brd 'branch -d'
|
|
git_alias brD 'branch -D'
|
|
git_alias wipe $'!sh -c \'git push $1 --delete $2\' -'
|
|
git_alias rename "branch -m"
|
|
git_alias brl "for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'"
|
|
git_alias copy 'branch --copy'
|
|
|
|
git_alias co checkout
|
|
git_alias cob "checkout -b"
|
|
git_alias sw switch
|
|
git_alias mr $'!sh -c \'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2\' -'
|
|
git_alias pr $'!sh -c \'git fetch $1 pull/$2/head:pr-$1-$2 && git checkout pr-$1-$2\' -'
|
|
|
|
git_alias ci commit
|
|
git_alias cif "commit --fixup"
|
|
git_alias cia "commit --amend"
|
|
git_alias cian "commit --amend --no-edit -a"
|
|
git_alias cim "commit -m"
|
|
git_alias ciw "commit -m WIP"
|
|
|
|
git_alias f fetch
|
|
git_alias fp "fetch -p"
|
|
git_alias fpa "fetch -p --all"
|
|
git_alias fpo "fetch -p origin"
|
|
|
|
git_alias pu $'!sh -c \'git push origin $(git branch --show-current)\''
|
|
git_alias puf $'!sh -c \'git push -f origin $(git branch --show-current)\''
|
|
|
|
git_alias rb rebase
|
|
git_alias rbi "rebase -i --autosquash"
|
|
git_alias rbim "rebase -i --autosquash $MASTER"
|
|
git_alias rba "rebase --abort"
|
|
git_alias rbc "rebase --continue"
|
|
git_alias rbs "rebase --skip"
|
|
git_alias rbm "rebase $MASTER"
|
|
|
|
git_alias unstage "reset HEAD --"
|
|
git_alias undo "reset --soft HEAD^"
|
|
|
|
git_alias ls "log --oneline"
|
|
git_alias lsd 'log --pretty=format:"%ad %C(yellow)%h%C(reset) %s" --date=short'
|
|
git_alias lsda 'log --pretty=format:"%ad %C(yellow)%h %C(Cyan)[%an]%C(reset) %s" --date=short'
|
|
git_alias slog "log --stat"
|
|
git_alias lola "log --graph --decorate --pretty=oneline --abbrev-commit --all --date=local"
|
|
git_alias hs "log --pretty='%C(yellow)%h %C(cyan)%cd %Cblue%aN%C(auto)%d %Creset%s' --graph --date=relative --date-order"
|
|
|
|
git_alias sh stash
|
|
git_alias shs "stash save"
|
|
git_alias shl "stash list"
|
|
git_alias sha "stash apply"
|
|
git_alias shp "stash pop"
|
|
git_alias shd "stash drop"
|
|
|
|
git_alias aliases "config --get-regexp alias"
|
|
git_alias configs "config --list"
|
|
|
|
#if can_run diff-so-fancy; then
|
|
# activate_diff_so_fancy
|
|
#fi
|
|
|
|
if can_run delta; then
|
|
log "Activate delta"
|
|
activate_delta
|
|
fi
|