From 1d9567d76b39a67b5be37f82e643920380ef5468 Mon Sep 17 00:00:00 2001 From: lachtan Date: Sat, 5 Feb 2022 19:47:45 +0100 Subject: [PATCH] Improve git config script Use function for logging Use function for check if binary exists --- scripts/git-config.sh | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/git-config.sh b/scripts/git-config.sh index 096e159..867702e 100755 --- a/scripts/git-config.sh +++ b/scripts/git-config.sh @@ -12,10 +12,17 @@ else DRY=false fi +function run() { + echo "$*" + if [[ $DRY != "true" ]]; then + "$@" + fi +} + function git_alias() { local name="$1" - local body="$2" - git_set "alias.$name" "$body" + local value="$2" + git_set "alias.$name" "$value" } function git_unalias() { @@ -26,25 +33,17 @@ function git_unalias() { function git_set() { local name="$1" local value="$2" - echo "git config --global $name $value" - if [[ $DRY != "true" ]]; then - git config --global "$name" "$value" - fi + run git config --global "$name" "$value" } function git_unset() { local name="$1" - echo "git config --global --unset $name" - if [[ $DRY != "true" ]]; then - git config --global --unset "$name" - fi + run git config --global --unset "$name" } -function git_unset_if_not_set() { - local name="$1" - if ! git config "$name"; then - git_unset "$name" - fi +function can_run() { + local application="$1" + command -v "$application" > /dev/null } git config --global core.editor vim @@ -104,7 +103,7 @@ 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 +if can_run diff-so-fancy; then git_set core.pager "diff-so-fancy | less --tabs=4 -RFX" git_set interactive.diffFilter "diff-so-fancy --patch" @@ -122,7 +121,6 @@ if command -v diff-so-fancy > /dev/null; then 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