diff --git a/scripts/git-config.sh b/scripts/git-config.sh index 6ba8c3a..e468245 100755 --- a/scripts/git-config.sh +++ b/scripts/git-config.sh @@ -6,18 +6,44 @@ ORIGIN=origin UPSTREAM=$ORIGIN MASTER=$UPSTREAM/master -if [[ $# > 0 && "$1" == "-dry" ]]; then +if [[ $# -gt 0 && "$1" == "-dry" ]]; then DRY=true else DRY=false fi function git_alias() { - name=$1 - body="$2" - echo "git config --global alias.$name $body" + local name="$1" + local body="$2" + git_set "alias.$name" "$body" +} + +function git_unalias() { + local name="$1" + git_unset "alias.$name" +} + +function git_set() { + local name="$1" + local value="$2" + echo "git config --global $name $value" if [[ $DRY != "true" ]]; then - git config --global alias.$name "$body" + git config --global "$name" "$value" + fi +} + +function git_unset() { + local name="$1" + echo "git config --global --unset $name" + if [[ $DRY != "true" ]]; then + git config --global --unset "$name" + fi +} + +function git_unset_if_not_set() { + local name="$1" + if ! git config "$name"; then + git_unset "$name" fi } @@ -77,3 +103,26 @@ git_alias shd "stash drop" git_alias aliases "config --get-regexp alias" git_alias configs "config --list" +if command -v diff-so-fancy > /dev/null; then + git_set core.pager "diff-so-fancy | less --tabs=4 -RFX" + git_set interactive.diffFilter "diff-so-fancy --patch" + + 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" + +else + git_unset core.pager + git_unset interactive.diffFilter +fi