76 lines
1.8 KiB
Bash
76 lines
1.8 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage:
|
|
git.sh show
|
|
git.sh editor [code|nvim]
|
|
EOF
|
|
}
|
|
|
|
set_editor() {
|
|
local editor_name="${1:-code}"
|
|
|
|
case "$editor_name" in
|
|
code)
|
|
git config --global core.editor "code --wait"
|
|
printf 'Set git core.editor to: %s\n' 'code --wait'
|
|
;;
|
|
nvim)
|
|
git config --global core.editor "nvim"
|
|
printf 'Set git core.editor to: %s\n' 'nvim'
|
|
;;
|
|
*)
|
|
printf 'Unknown editor: %s\n' "$editor_name" >&2
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
show_config() {
|
|
local name email editor
|
|
local helpers=()
|
|
local helper
|
|
|
|
name="$(git config --global --get user.name || true)"
|
|
email="$(git config --global --get user.email || true)"
|
|
editor="$(git config --global --get core.editor || true)"
|
|
|
|
while IFS= read -r helper; do
|
|
[ -n "$helper" ] && helpers+=("$helper")
|
|
done < <(git config --global --get-all credential.helper || true)
|
|
|
|
printf 'Global git config\n'
|
|
printf ' user.name %s\n' "${name:-<unset>}"
|
|
printf ' user.email %s\n' "${email:-<unset>}"
|
|
printf ' core.editor %s\n' "${editor:-<unset>}"
|
|
|
|
if [ "${#helpers[@]}" -eq 0 ]; then
|
|
printf ' credential.helper %s\n' '<unset>'
|
|
else
|
|
printf ' credential.helper %s\n' "${helpers[0]}"
|
|
if [ "${#helpers[@]}" -gt 1 ]; then
|
|
local index
|
|
for (( index=1; index<${#helpers[@]}; index++ )); do
|
|
printf ' %s\n' "${helpers[$index]}"
|
|
done
|
|
fi
|
|
fi
|
|
}
|
|
|
|
case "${1:-show}" in
|
|
show)
|
|
show_config
|
|
;;
|
|
editor)
|
|
set_editor "${2:-code}"
|
|
;;
|
|
*)
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
esac
|