-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·100 lines (82 loc) · 2.42 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·100 lines (82 loc) · 2.42 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
#!/usr/bin/env bash
# ghctx installer
set -euo pipefail
INSTALL_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/gh"
SCRIPT_NAME="gh-context.sh"
main() {
echo "Installing ghctx..."
# Check for gh CLI
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed."
echo "Install it from: https://cli.github.com/"
exit 1
fi
# Check gh version
local gh_version
gh_version=$(gh --version | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
local major minor
major=$(echo "$gh_version" | cut -d. -f1)
minor=$(echo "$gh_version" | cut -d. -f2)
if [[ "$major" -lt 2 ]] || [[ "$major" -eq 2 && "$minor" -lt 40 ]]; then
echo "Warning: gh version $gh_version detected. Version 2.40.0+ recommended for multi-account support."
fi
# Create directory
mkdir -p "$INSTALL_DIR"
# Determine script location (local or remote)
local script_path
script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$SCRIPT_NAME"
if [[ -f "$script_path" ]]; then
# Local install
cp "$script_path" "$INSTALL_DIR/$SCRIPT_NAME"
else
# Remote install
echo "Downloading $SCRIPT_NAME..."
curl -fsSL "https://raw.githubusercontent.com/jasonwbarnett/ghctx/main/$SCRIPT_NAME" \
-o "$INSTALL_DIR/$SCRIPT_NAME"
fi
chmod 644 "$INSTALL_DIR/$SCRIPT_NAME"
echo "Installed to: $INSTALL_DIR/$SCRIPT_NAME"
echo ""
echo "Add the following to your shell config:"
echo ""
# Detect shell
local shell_name
shell_name=$(basename "$SHELL")
case "$shell_name" in
bash)
cat <<'EOF'
# ~/.bashrc
source ~/.config/gh/gh-context.sh
# Optional: auto-switch based on .ghcontext files
PROMPT_COMMAND="_ghctx_auto; $PROMPT_COMMAND"
# Optional: show context in prompt
PS1='$(ghctx_prompt)'"$PS1"
EOF
;;
zsh)
cat <<'EOF'
# ~/.zshrc
source ~/.config/gh/gh-context.sh
# Optional: auto-switch based on .ghcontext files
precmd_functions+=(_ghctx_auto)
# Optional: show context in prompt
PS1='$(ghctx_prompt)'"$PS1"
EOF
;;
*)
cat <<EOF
# Add to your shell config:
source ~/.config/gh/gh-context.sh
EOF
;;
esac
echo ""
echo "Then restart your shell or run: source ~/.config/gh/gh-context.sh"
echo ""
echo "Quick start:"
echo " ghctx new personal # Create context from current gh auth"
echo " ghctx list # List all contexts"
echo " ghctx use personal # Switch to context"
echo " ghctx bind personal # Bind current repo to context"
}
main "$@"