-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathgit-gtr
More file actions
executable file
·129 lines (119 loc) · 2.62 KB
/
git-gtr
File metadata and controls
executable file
·129 lines (119 loc) · 2.62 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
#!/usr/bin/env bash
# git-gtr - Git worktree runner
# Portable, cross-platform git worktree management
# Invoked as: git gtr <command> (git subcommand via PATH discovery)
set -e
# Debug: show file:line:function on set -e failures
if [ -n "${GTR_DEBUG:-}" ]; then
trap 'printf "ERROR at %s:%s in %s()\n" "${BASH_SOURCE[0]}" "$LINENO" "${FUNCNAME[0]:-main}" >&2' ERR
fi
# Version
GTR_VERSION="2.6.0"
# Find the script directory (resolve symlinks; allow env override)
resolve_script_dir() {
local src="${BASH_SOURCE[0]}"
while [ -h "$src" ]; do
local dir
dir="$(cd -P "$(dirname "$src")" && pwd)"
src="$(readlink "$src")"
[[ "$src" != /* ]] && src="$dir/$src"
done
cd -P "$(dirname "$src")/.." && pwd
}
: "${GTR_DIR:=$(resolve_script_dir)}"
# Source library files
. "$GTR_DIR/lib/ui.sh"
. "$GTR_DIR/lib/args.sh"
. "$GTR_DIR/lib/config.sh"
_ui_apply_color_config
. "$GTR_DIR/lib/platform.sh"
. "$GTR_DIR/lib/core.sh"
. "$GTR_DIR/lib/copy.sh"
. "$GTR_DIR/lib/hooks.sh"
. "$GTR_DIR/lib/provider.sh"
. "$GTR_DIR/lib/adapters.sh"
. "$GTR_DIR/lib/launch.sh"
# Source command handlers
for _cmd_file in "$GTR_DIR"/lib/commands/*.sh; do
# shellcheck disable=SC1090
. "$_cmd_file"
done
unset _cmd_file
# Main dispatcher
main() {
local cmd="${1:-help}"
shift 2>/dev/null || true
# Set for per-command help (used by show_command_help in ui.sh)
_GTR_CURRENT_COMMAND="$cmd"
case "$cmd" in
new)
cmd_create "$@"
;;
rm)
cmd_remove "$@"
;;
mv|rename)
cmd_rename "$@"
;;
go)
cmd_go "$@"
;;
run)
cmd_run "$@"
;;
editor)
cmd_editor "$@"
;;
ai)
cmd_ai "$@"
;;
copy)
cmd_copy "$@"
;;
ls|list)
cmd_list "$@"
;;
clean)
cmd_clean "$@"
;;
doctor)
cmd_doctor "$@"
;;
adapter|adapters)
cmd_adapter "$@"
;;
config)
cmd_config "$@"
;;
completion)
cmd_completion "$@"
;;
init)
cmd_init "$@"
;;
trust)
cmd_trust "$@"
;;
version|--version|-v)
echo "git gtr version $GTR_VERSION"
;;
help|--help|-h)
cmd_help "$@"
;;
cd)
local _shell_name
_shell_name="$(basename "${SHELL:-bash}")"
log_error "'cd' requires shell integration (subprocesses cannot change your shell's directory)"
log_info "Run 'git gtr help init' for setup instructions"
log_info "Then use: gtr cd [<branch>]"
exit 1
;;
*)
log_error "Unknown command: $cmd"
echo "Use 'git gtr help' for available commands"
exit 1
;;
esac
}
# Run main
main "$@"