~kris/dots

srice

ref: ff7367cb2ef828502c3f7fde003f45d5daa33206 srice/.local/bin/git -rw-r--r-- 1.6 KiB
ff7367cb — Kris Yotam add ram memory visualization script 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#
# ───────────────────────────────────────────────
#  Kris Yotam (aka. khr1st) — Git Profile Switcher
#  Location: ~/.local/bin/git
#  License: MIT
#  Purpose:
#      Select a git profile by name and set global
#      author/committer name + email accordingly.
#
#  Usage:
#      git <profile>
#        Ex: git krisyotam
#            git khr1st
#
#  Dependencies: POSIX shell, git
#  Profiles File: ~/.config/git-profiles
#     Format (key=value per line):
#         [profile]
#         name=Your Name
#         email=your@email
#
#  Date: 2025-09-29
# ───────────────────────────────────────────────
#

PROFILES_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/git-profiles"

usage() {
    echo "Usage: git <profile>"
    echo "Profiles are defined in: $PROFILES_FILE"
    exit 1
}

[ $# -ne 1 ] && usage
PROFILE="$1"

# Parse the profiles file
if ! grep -q "^\[$PROFILE\]" "$PROFILES_FILE" 2>/dev/null; then
    echo "Profile '$PROFILE' not found in $PROFILES_FILE"
    exit 1
fi

NAME=$(awk -F= -v p="[$PROFILE]" '
    $0 == p {f=1; next}
    f && /^name=/ {print $2; exit}
' "$PROFILES_FILE")

EMAIL=$(awk -F= -v p="[$PROFILE]" '
    $0 == p {f=1; next}
    f && /^email=/ {print $2; exit}
' "$PROFILES_FILE")

if [ -z "$NAME" ] || [ -z "$EMAIL" ]; then
    echo "Incomplete config for '$PROFILE'"
    exit 1
fi

git config --global user.name "$NAME"
git config --global user.email "$EMAIL"

echo "Active git profile: $PROFILE"
echo "  Name : $NAME"
echo "  Email: $EMAIL"