Improve git config script

Use function for logging
Use function for check if binary exists
This commit is contained in:
lachtan
2022-02-05 19:47:45 +01:00
parent 2f768d46e7
commit 1d9567d76b

View File

@@ -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