-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-user
More file actions
executable file
·649 lines (538 loc) · 21.2 KB
/
git-user
File metadata and controls
executable file
·649 lines (538 loc) · 21.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#!/usr/bin/env bash
#
# git-user — CLI tool to switch between Git/GitHub user profiles
#
# Manages multiple git identities (personal, work, etc.) with:
# • Persistent config stored in ~/.git_user.conf
# • Automatic git global user.name / user.email switching
# • Automatic gh auth switching
#
# Usage:
# git-user add <profile> Add a new profile
# git-user remove <profile> Remove a profile
# git-user list List all profiles
# git-user switch <profile> Switch to a profile
# git-user current Show active profile
# git-user edit <profile> Edit an existing profile
# git-user help Show help
set -euo pipefail
CONF_FILE="${GIT_USER_CONF:-$HOME/.git_user.conf}"
SSH_CONFIG_FILE="${GIT_USER_SSH_CONFIG:-$HOME/.ssh/config}"
VERSION="1.1.0"
# ─── Colors ───────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m' # No Color
# ─── Helpers ──────────────────────────────────────────────────────────────────
info() { echo -e "${BLUE}ℹ${NC} $*"; }
success() { echo -e "${GREEN}✔${NC} $*"; }
warn() { echo -e "${YELLOW}⚠${NC} $*"; }
error() { echo -e "${RED}✖${NC} $*" >&2; }
die() { error "$@"; exit 1; }
ensure_conf() {
if [[ ! -f "$CONF_FILE" ]]; then
cat > "$CONF_FILE" <<'EOF'
# git-user configuration file
# Format: profile.key=value
# Keys: name, email, gh_user, org_name (optional), ssh_key (optional), remote_host (optional)
# Example:
# personal.name=John Doe
# personal.email=john@gmail.com
# personal.gh_user=johndoe
# personal.org_name=johndoe
# personal.ssh_key=~/.ssh/id_ed25519_personal
# personal.remote_host=github.com
#
# Active profile is stored as:
# _active=personal
EOF
info "Created config file at ${CYAN}$CONF_FILE${NC}"
fi
}
conf_get() {
# conf_get <key> — returns value or empty string
local key="$1"
grep -m1 "^${key}=" "$CONF_FILE" 2>/dev/null | cut -d'=' -f2- || true
}
conf_set() {
# conf_set <key> <value> — portable across macOS (BSD sed) and Linux (GNU sed)
local key="$1" value="$2"
if grep -q "^${key}=" "$CONF_FILE" 2>/dev/null; then
local tmpfile
tmpfile=$(mktemp)
awk -v k="$key" -v v="$value" 'BEGIN{FS=OFS="="} $1==k{$0=k"="v} {print}' "$CONF_FILE" > "$tmpfile"
mv "$tmpfile" "$CONF_FILE"
else
echo "${key}=${value}" >> "$CONF_FILE"
fi
}
conf_delete_profile() {
local profile="$1"
local tmpfile
tmpfile=$(mktemp)
grep -v "^${profile}\." "$CONF_FILE" > "$tmpfile" || true
mv "$tmpfile" "$CONF_FILE"
}
profile_exists() {
grep -q "^${1}\." "$CONF_FILE" 2>/dev/null
}
list_profiles() {
sed -n 's/^\([a-zA-Z0-9_-]*\)\..*/\1/p' "$CONF_FILE" 2>/dev/null | sort -u
}
require_profile() {
local profile="$1"
if ! profile_exists "$profile"; then
die "Profile '${BOLD}$profile${NC}' not found. Run ${CYAN}git-user list${NC} to see available profiles."
fi
}
extract_remote_owner() {
local remote_url="${1:-}"
local repo_path=""
case "$remote_url" in
git@*:* )
repo_path="${remote_url#*:}"
;;
ssh://git@*/* )
repo_path="${remote_url#ssh://git@*/}"
;;
https://*/* )
repo_path="${remote_url#https://*/}"
;;
esac
repo_path="${repo_path%.git}"
if [[ "$repo_path" == */* ]]; then
printf '%s\n' "${repo_path%%/*}"
fi
}
profile_for_gh_user() {
local target_gh_user="$1"
local profile profile_gh_user
while IFS= read -r profile; do
[[ -n "$profile" ]] || continue
profile_gh_user=$(conf_get "${profile}.gh_user")
if [[ "$profile_gh_user" == "$target_gh_user" ]]; then
printf '%s\n' "$profile"
return 0
fi
done < <(list_profiles)
return 1
}
profile_target_owner() {
local profile="$1"
local owner gh_user
owner=$(conf_get "${profile}.org_name")
gh_user=$(conf_get "${profile}.gh_user")
printf '%s\n' "${owner:-$gh_user}"
}
sanitize_alias_part() {
local value="${1:-}"
value=$(printf '%s' "$value" | tr '[:upper:]' '[:lower:]')
value=$(printf '%s' "$value" | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//; s/-+/-/g')
printf '%s\n' "${value:-default}"
}
ssh_alias_name() {
local profile="$1" remote_host="$2"
printf 'git-user-%s-%s\n' "$(sanitize_alias_part "$profile")" "$(sanitize_alias_part "$remote_host")"
}
extract_remote_path() {
local remote_url="${1:-}"
local repo_path=""
case "$remote_url" in
git@*:* )
repo_path="${remote_url#*:}"
;;
ssh://git@*/* )
repo_path="${remote_url#ssh://git@*/}"
;;
https://*/* )
repo_path="${remote_url#https://*/}"
;;
esac
repo_path="${repo_path%.git}"
printf '%s\n' "$repo_path"
}
build_remote_url() {
local current_remote="$1" remote_host="$2" target_owner="$3" repo_name="$4"
case "$current_remote" in
https://* )
printf 'https://%s/%s/%s.git\n' "$remote_host" "$target_owner" "$repo_name"
;;
ssh://git@* )
printf 'ssh://git@%s/%s/%s.git\n' "$remote_host" "$target_owner" "$repo_name"
;;
* )
printf 'git@%s:%s/%s.git\n' "$remote_host" "$target_owner" "$repo_name"
;;
esac
}
ensure_ssh_config_file() {
local ssh_dir
ssh_dir=$(dirname "$SSH_CONFIG_FILE")
mkdir -p "$ssh_dir"
chmod 700 "$ssh_dir" 2>/dev/null || true
touch "$SSH_CONFIG_FILE"
chmod 600 "$SSH_CONFIG_FILE" 2>/dev/null || true
}
remove_ssh_alias_block() {
local profile="$1" remote_host="$2"
local start_marker="# >>> git-user profile:${profile} host:${remote_host} >>>"
local end_marker="# <<< git-user profile:${profile} host:${remote_host} <<<"
local tmpfile
[[ -f "$SSH_CONFIG_FILE" ]] || return 0
tmpfile=$(mktemp)
awk -v start="$start_marker" -v end="$end_marker" '
$0 == start { skip = 1; next }
$0 == end { skip = 0; next }
!skip { print }
' "$SSH_CONFIG_FILE" > "$tmpfile"
mv "$tmpfile" "$SSH_CONFIG_FILE"
}
upsert_ssh_alias() {
local profile="$1" remote_host="$2" ssh_key="$3"
local expanded_key="${ssh_key/#\~/$HOME}"
local alias_name start_marker end_marker
[[ -f "$expanded_key" ]] || return 1
alias_name=$(ssh_alias_name "$profile" "$remote_host")
start_marker="# >>> git-user profile:${profile} host:${remote_host} >>>"
end_marker="# <<< git-user profile:${profile} host:${remote_host} <<<"
ensure_ssh_config_file
remove_ssh_alias_block "$profile" "$remote_host"
{
echo "$start_marker"
echo "Host $alias_name"
echo " HostName $remote_host"
echo " User git"
if should_add_keys_to_agent; then
echo " AddKeysToAgent yes"
fi
if should_use_keychain_directive; then
echo " UseKeychain yes"
fi
echo " IdentityFile $expanded_key"
echo " IdentitiesOnly yes"
echo "$end_marker"
} >> "$SSH_CONFIG_FILE"
printf '%s\n' "$alias_name"
}
should_add_keys_to_agent() {
case "$(uname -s 2>/dev/null || echo unknown)" in
Darwin|MINGW*|MSYS*|CYGWIN*)
return 0
;;
esac
case "${GIT_USER_SSH_USE_KEYCHAIN:-}" in
1|true|TRUE|yes|YES)
return 0
;;
esac
return 1
}
should_use_keychain_directive() {
case "$(uname -s 2>/dev/null || echo unknown)" in
Darwin)
return 0
;;
esac
case "${GIT_USER_SSH_USE_KEYCHAIN:-}" in
1|true|TRUE|yes|YES)
return 0
;;
esac
return 1
}
clear_managed_git_ssh_aliases() {
local profile remote_host alias_name
while IFS= read -r profile; do
[[ -n "$profile" ]] || continue
remote_host=$(conf_get "${profile}.remote_host")
remote_host="${remote_host:-github.com}"
alias_name=$(ssh_alias_name "$profile" "$remote_host")
git config --global --remove-section "url.git@${alias_name}:" 2>/dev/null || true
git config --global --remove-section "url.ssh://git@${alias_name}/" 2>/dev/null || true
done < <(list_profiles)
}
activate_git_ssh_alias() {
local alias_name="$1" remote_host="$2"
clear_managed_git_ssh_aliases
git config --global url."git@${alias_name}:".insteadOf "git@${remote_host}:"
git config --global url."ssh://git@${alias_name}/".insteadOf "ssh://git@${remote_host}/"
}
prompt_value() {
local prompt="$1" default="${2:-}"
local value
if [[ -n "$default" ]]; then
read -rp "$(echo -e "${BOLD}$prompt${NC} ${DIM}[$default]${NC}: ")" value
echo "${value:-$default}"
else
read -rp "$(echo -e "${BOLD}$prompt${NC}: ")" value
echo "$value"
fi
}
# ─── Commands ─────────────────────────────────────────────────────────────────
cmd_add() {
local profile="${1:-}"
[[ -z "$profile" ]] && die "Usage: git-user add <profile-name>"
if profile_exists "$profile"; then
die "Profile '${BOLD}$profile${NC}' already exists. Use ${CYAN}git-user edit $profile${NC} to modify it."
fi
echo -e "\n${BOLD}Adding profile: ${CYAN}$profile${NC}\n"
local name email gh_user org_name ssh_key remote_host
name=$(prompt_value " Full name" "")
[[ -z "$name" ]] && die "Name is required."
email=$(prompt_value " Email" "")
[[ -z "$email" ]] && die "Email is required."
gh_user=$(prompt_value " GitHub username" "")
[[ -z "$gh_user" ]] && die "GitHub username is required."
org_name=$(prompt_value " Org name / repo owner" "$gh_user")
ssh_key=$(prompt_value " SSH key path (optional)" "")
remote_host=$(prompt_value " Remote host (optional)" "github.com")
conf_set "${profile}.name" "$name"
conf_set "${profile}.email" "$email"
conf_set "${profile}.gh_user" "$gh_user"
conf_set "${profile}.org_name" "${org_name:-$gh_user}"
[[ -n "$ssh_key" ]] && conf_set "${profile}.ssh_key" "$ssh_key"
conf_set "${profile}.remote_host" "${remote_host:-github.com}"
echo ""
success "Profile '${BOLD}$profile${NC}' added successfully!"
echo ""
}
cmd_edit() {
local profile="${1:-}"
[[ -z "$profile" ]] && die "Usage: git-user edit <profile-name>"
require_profile "$profile"
echo -e "\n${BOLD}Editing profile: ${CYAN}$profile${NC}\n"
local name email gh_user org_name ssh_key remote_host
name=$(prompt_value " Full name" "$(conf_get "${profile}.name")")
email=$(prompt_value " Email" "$(conf_get "${profile}.email")")
gh_user=$(prompt_value " GitHub username" "$(conf_get "${profile}.gh_user")")
org_name=$(prompt_value " Org name / repo owner" "$(profile_target_owner "$profile")")
ssh_key=$(prompt_value " SSH key path" "$(conf_get "${profile}.ssh_key")")
remote_host=$(prompt_value " Remote host" "$(conf_get "${profile}.remote_host")")
conf_set "${profile}.name" "$name"
conf_set "${profile}.email" "$email"
conf_set "${profile}.gh_user" "$gh_user"
conf_set "${profile}.org_name" "${org_name:-$gh_user}"
[[ -n "$ssh_key" ]] && conf_set "${profile}.ssh_key" "$ssh_key"
conf_set "${profile}.remote_host" "${remote_host:-github.com}"
echo ""
success "Profile '${BOLD}$profile${NC}' updated!"
echo ""
}
cmd_remove() {
local profile="${1:-}"
[[ -z "$profile" ]] && die "Usage: git-user remove <profile-name>"
require_profile "$profile"
local active
active=$(conf_get "_active")
read -rp "$(echo -e "${YELLOW}Remove profile '${BOLD}$profile${NC}${YELLOW}'? [y/N]:${NC} ")" confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { info "Cancelled."; return; }
local remote_host
remote_host=$(conf_get "${profile}.remote_host")
remote_host="${remote_host:-github.com}"
conf_delete_profile "$profile"
remove_ssh_alias_block "$profile" "$remote_host"
if [[ "$active" == "$profile" ]]; then
local tmpfile
tmpfile=$(mktemp)
grep -v "^_active=" "$CONF_FILE" > "$tmpfile" || true
mv "$tmpfile" "$CONF_FILE"
clear_managed_git_ssh_aliases
git config --global --unset core.sshCommand 2>/dev/null || true
warn "Removed active profile. No profile is currently active."
fi
success "Profile '${BOLD}$profile${NC}' removed."
}
cmd_list() {
local profiles active
active=$(conf_get "_active")
profiles=$(list_profiles)
if [[ -z "$profiles" ]]; then
warn "No profiles configured. Run ${CYAN}git-user add <name>${NC} to create one."
return
fi
echo -e "\n${BOLD} Profiles${NC} ${DIM}($CONF_FILE)${NC}\n"
while IFS= read -r p; do
local marker=" "
local color=""
if [[ "$p" == "$active" ]]; then
marker="●"
color="${GREEN}"
fi
local name email gh_user
name=$(conf_get "${p}.name")
email=$(conf_get "${p}.email")
gh_user=$(conf_get "${p}.gh_user")
if [[ "$p" == "$active" ]]; then
echo -e " ${GREEN}${marker}${NC} ${GREEN}${BOLD}${p}${NC} ${DIM}${name} <${email}> @${gh_user}${NC}"
else
echo -e " ${DIM}${marker}${NC} ${BOLD}${p}${NC} ${DIM}${name} <${email}> @${gh_user}${NC}"
fi
done <<< "$profiles"
echo ""
}
cmd_current() {
local active
active=$(conf_get "_active")
if [[ -z "$active" ]]; then
warn "No active profile. Run ${CYAN}git-user switch <profile>${NC}."
echo ""
echo -e " ${DIM}Current git config:${NC}"
echo -e " ${DIM} user.name = $(git config --global user.name 2>/dev/null || echo '(not set)')${NC}"
echo -e " ${DIM} user.email = $(git config --global user.email 2>/dev/null || echo '(not set)')${NC}"
echo ""
return
fi
local name email gh_user
name=$(conf_get "${active}.name")
email=$(conf_get "${active}.email")
gh_user=$(conf_get "${active}.gh_user")
echo -e "\n ${GREEN}●${NC} Active profile: ${GREEN}${BOLD}$active${NC}"
echo -e " Name: $name"
echo -e " Email: $email"
echo -e " GitHub: @$gh_user"
echo ""
}
cmd_switch() {
local profile="${1:-}"
[[ -z "$profile" ]] && die "Usage: git-user switch <profile-name>"
require_profile "$profile"
local name email gh_user target_owner ssh_key remote_host
name=$(conf_get "${profile}.name")
email=$(conf_get "${profile}.email")
gh_user=$(conf_get "${profile}.gh_user")
target_owner=$(profile_target_owner "$profile")
ssh_key=$(conf_get "${profile}.ssh_key")
remote_host=$(conf_get "${profile}.remote_host")
remote_host="${remote_host:-github.com}"
echo -e "\n${BOLD}Switching to profile: ${CYAN}$profile${NC}\n"
# 1) Git global config
echo -e " ${DIM}Setting git config...${NC}"
git config --global user.name "$name"
git config --global user.email "$email"
success "git config → ${BOLD}$name${NC} <${email}>"
# 2) GitHub CLI auth switch
if command -v gh &>/dev/null; then
echo -e " ${DIM}Switching gh auth...${NC}"
# Check if user is already logged in on gh
local current_gh_user
current_gh_user=$(gh api --hostname "$remote_host" user --jq '.login' 2>/dev/null || true)
if [[ "$current_gh_user" == "$gh_user" ]]; then
success "gh auth → already logged in as ${BOLD}@$gh_user${NC}"
else
# Try to switch to an existing auth token
if gh auth switch --user "$gh_user" --hostname "$remote_host" 2>/dev/null; then
current_gh_user=$(gh api --hostname "$remote_host" user --jq '.login' 2>/dev/null || true)
if [[ "$current_gh_user" == "$gh_user" ]]; then
success "gh auth → switched to ${BOLD}@$gh_user${NC}"
else
warn "gh auth → selected @$gh_user, but the token could not be verified. Run ${CYAN}gh auth login --hostname $remote_host${NC} if HTTPS git fails."
fi
else
warn "gh auth: user @$gh_user not found. Starting login..."
echo -e " ${DIM}Run: gh auth login --hostname $remote_host${NC}"
gh auth login --hostname "$remote_host" || warn "gh auth login was skipped or failed."
fi
fi
else
warn "gh CLI not found — skipping GitHub auth switch."
fi
# 3) SSH key / SSH alias
if [[ -n "$ssh_key" ]]; then
local alias_name
alias_name=$(upsert_ssh_alias "$profile" "$remote_host" "$ssh_key" || true)
if [[ -n "$alias_name" ]]; then
activate_git_ssh_alias "$alias_name" "$remote_host"
git config --global --unset core.sshCommand 2>/dev/null || true
success "SSH alias → ${BOLD}$alias_name${NC} (${DIM}$ssh_key${NC})"
else
warn "SSH key not found at $ssh_key — skipping."
fi
else
clear_managed_git_ssh_aliases
git config --global --unset core.sshCommand 2>/dev/null || true
info "SSH alias → cleared managed git SSH routing"
fi
# 4) Update remote owner for current repo
if git rev-parse --is-inside-work-tree &>/dev/null; then
local current_remote repo_path repo_name current_owner owner_profile new_remote
current_remote=$(git config --get remote.origin.url 2>/dev/null || true)
repo_path=$(extract_remote_path "$current_remote")
current_owner=$(extract_remote_owner "$current_remote")
owner_profile=$(profile_for_gh_user "$current_owner" || true)
if [[ -n "$current_remote" ]]; then
repo_name="${repo_path##*/}"
if [[ -n "$repo_name" ]]; then
new_remote=$(build_remote_url "$current_remote" "$remote_host" "$target_owner" "$repo_name")
if [[ "$current_remote" != "$new_remote" ]]; then
git remote set-url origin "$new_remote"
success "remote origin → ${BOLD}$new_remote${NC}"
current_owner="$target_owner"
owner_profile=$(profile_for_gh_user "$current_owner" || true)
else
info "remote origin → already using ${BOLD}${target_owner}/${repo_name}${NC}"
fi
fi
if [[ "$current_remote" == git@* || "$current_remote" == ssh://git@* ]]; then
info "Repo remote uses SSH, so git push/pull will use the active git-user SSH alias."
fi
if [[ -n "$owner_profile" && "$owner_profile" != "$profile" ]]; then
warn "origin owner maps to configured profile ${BOLD}$owner_profile${NC}, but the active profile is ${BOLD}$profile${NC}. Push/pull may fail unless the active account also has access."
fi
else
info "No 'origin' remote found — skipping remote update."
fi
fi
# 5) Save active profile
conf_set "_active" "$profile"
echo -e "\n${GREEN}${BOLD} ✔ Switched to '$profile'${NC}\n"
}
cmd_help() {
cat <<EOF
$(echo -e "${BOLD}git-user${NC} v${VERSION} — Manage multiple Git/GitHub identities")
$(echo -e "${BOLD}USAGE${NC}")
git-user <command> [arguments]
$(echo -e "${BOLD}COMMANDS${NC}")
add <profile> Create a new profile (name, email, gh user, ssh key)
remove <profile> Delete a profile
edit <profile> Modify an existing profile
list Show all profiles (● = active)
switch <profile> Activate a profile:
• Sets git global user.name & user.email
• Switches gh CLI auth
• Activates a managed SSH alias (if set)
• Updates current repo's origin owner (if inside a repo)
current Show the active profile
help Show this help message
$(echo -e "${BOLD}CONFIG${NC}")
Profiles stored in: ${CONF_FILE}
Override with: GIT_USER_CONF=/path/to/file git-user ...
$(echo -e "${BOLD}EXAMPLES${NC}")
git-user add personal
git-user add work
git-user switch personal
git-user list
EOF
}
# ─── Main ─────────────────────────────────────────────────────────────────────
main() {
ensure_conf
local cmd="${1:-help}"
shift || true
case "$cmd" in
add) cmd_add "$@" ;;
remove|rm|delete) cmd_remove "$@" ;;
edit) cmd_edit "$@" ;;
list|ls) cmd_list "$@" ;;
switch|use|set) cmd_switch "$@" ;;
current|who|status) cmd_current "$@" ;;
help|--help|-h) cmd_help ;;
version|--version|-v) echo "git-user v${VERSION}" ;;
*) die "Unknown command: $cmd. Run ${CYAN}git-user help${NC} for usage." ;;
esac
}
main "$@"