Improve git config script
Use function for logging Use function for check if binary exists
This commit is contained in:
@@ -12,10 +12,17 @@ else
|
|||||||
DRY=false
|
DRY=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
echo "$*"
|
||||||
|
if [[ $DRY != "true" ]]; then
|
||||||
|
"$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function git_alias() {
|
function git_alias() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local body="$2"
|
local value="$2"
|
||||||
git_set "alias.$name" "$body"
|
git_set "alias.$name" "$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_unalias() {
|
function git_unalias() {
|
||||||
@@ -26,25 +33,17 @@ function git_unalias() {
|
|||||||
function git_set() {
|
function git_set() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
echo "git config --global $name $value"
|
run git config --global "$name" "$value"
|
||||||
if [[ $DRY != "true" ]]; then
|
|
||||||
git config --global "$name" "$value"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_unset() {
|
function git_unset() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
echo "git config --global --unset $name"
|
run git config --global --unset "$name"
|
||||||
if [[ $DRY != "true" ]]; then
|
|
||||||
git config --global --unset "$name"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_unset_if_not_set() {
|
function can_run() {
|
||||||
local name="$1"
|
local application="$1"
|
||||||
if ! git config "$name"; then
|
command -v "$application" > /dev/null
|
||||||
git_unset "$name"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
git config --global core.editor vim
|
git config --global core.editor vim
|
||||||
@@ -104,7 +103,7 @@ git_alias shd "stash drop"
|
|||||||
git_alias aliases "config --get-regexp alias"
|
git_alias aliases "config --get-regexp alias"
|
||||||
git_alias configs "config --list"
|
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 core.pager "diff-so-fancy | less --tabs=4 -RFX"
|
||||||
git_set interactive.diffFilter "diff-so-fancy --patch"
|
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.old "red bold"
|
||||||
git_set color.diff.new "green bold"
|
git_set color.diff.new "green bold"
|
||||||
git_set color.diff.whitespace "red reverse"
|
git_set color.diff.whitespace "red reverse"
|
||||||
|
|
||||||
else
|
else
|
||||||
git_unset core.pager
|
git_unset core.pager
|
||||||
git_unset interactive.diffFilter
|
git_unset interactive.diffFilter
|
||||||
|
|||||||
Reference in New Issue
Block a user