-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·107 lines (94 loc) · 3.58 KB
/
Copy pathsetup
File metadata and controls
executable file
·107 lines (94 loc) · 3.58 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
#!/usr/bin/env sh
set -u
if ! command -v git >/dev/null 2>&1; then
printf 'setup: git not found on PATH\n' >&2
exit 1
fi
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
sibling_commit="$script_dir/git-ai-commit"
if [ -x "$sibling_commit" ]; then
alias_value="!\"$sibling_commit\""
elif command -v git-ai-commit >/dev/null 2>&1; then
alias_value='!git-ai-commit'
else
printf 'setup: git-ai-commit not found on PATH or at %s\n' "$sibling_commit" >&2
exit 1
fi
path_commit=$(command -v git-ai-commit 2>/dev/null || true)
if [ -n "$path_commit" ] && [ -x "$sibling_commit" ]; then
path_commit_real=$(CDPATH= cd -- "$(dirname -- "$path_commit")" && pwd)/$(basename -- "$path_commit")
sibling_commit_real=$(CDPATH= cd -- "$(dirname -- "$sibling_commit")" && pwd)/$(basename -- "$sibling_commit")
if [ "$path_commit_real" != "$sibling_commit_real" ]; then
printf 'setup: warning: git ai-commit will use %s before Git aliases\n' "$path_commit" >&2
printf 'setup: warning: unlink, uninstall, or upgrade that git-ai-commit executable if it is stale\n' >&2
fi
fi
current_editor=$(git config --global core.editor 2>/dev/null || true)
default_editor=${current_editor:-vim}
current_issue_prefix=$(git config --global ai-commit.issue-prefix 2>/dev/null || true)
default_issue_prefix=${current_issue_prefix:-}
current_backend=$(git config --global ai-commit.backend 2>/dev/null || true)
case $current_backend in
codex|cursor) default_backend=$current_backend ;;
*) default_backend=codex ;;
esac
printf 'Configure Git for git-ai-commit.\n'
printf 'AI backend: codex or cursor\n'
printf 'Backend [%s]: ' "$default_backend"
IFS= read -r backend
backend=${backend:-$default_backend}
case $backend in
codex)
if ! command -v codex >/dev/null 2>&1; then
printf 'setup: codex CLI not found on PATH\n' >&2
printf 'Install Codex CLI and rerun setup.\n' >&2
exit 1
fi
if ! codex --version >/dev/null 2>&1; then
printf 'setup: codex CLI is not working; `codex --version` failed\n' >&2
exit 1
fi
;;
cursor)
if ! command -v agent >/dev/null 2>&1; then
printf 'setup: cursor agent CLI not found on PATH\n' >&2
printf 'Install Cursor CLI from https://cursor.com/install and rerun setup.\n' >&2
exit 1
fi
if ! agent --version >/dev/null 2>&1; then
printf 'setup: cursor agent CLI is not working; `agent --version` failed\n' >&2
exit 1
fi
;;
*)
printf 'setup: unsupported backend: %s\n' "$backend" >&2
printf 'setup: choose codex or cursor\n' >&2
exit 1
;;
esac
printf 'Examples: vim, nano, code --wait, cursor --wait\n'
printf 'Git editor [%s]: ' "$default_editor"
IFS= read -r editor
editor=${editor:-$default_editor}
if [ -z "$(printf '%s' "$editor" | tr -d '[:space:]')" ]; then
printf 'setup: editor cannot be empty\n' >&2
exit 1
fi
printf 'Issue tracker prefix (e.g. AB#, JIRA-, GH-)\n'
printf 'Issue prefix [%s]: ' "$default_issue_prefix"
IFS= read -r issue_prefix
issue_prefix=${issue_prefix:-$default_issue_prefix}
git config --global core.editor "$editor"
git config --global ai-commit.issue-prefix "$issue_prefix"
git config --global ai-commit.backend "$backend"
git config --global alias.ai-commit "$alias_value"
printf '\nConfigured:\n'
case $backend in
codex) printf ' codex CLI = %s\n' "$(command -v codex)" ;;
cursor) printf ' cursor agent = %s\n' "$(command -v agent)" ;;
esac
printf ' core.editor = %s\n' "$editor"
printf ' ai-commit.issue-prefix = %s\n' "$issue_prefix"
printf ' ai-commit.backend = %s\n' "$backend"
printf ' alias.ai-commit = %s\n' "$alias_value"
printf '\nUse: git ai-commit\n'