-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·159 lines (137 loc) · 4.31 KB
/
install.sh
File metadata and controls
executable file
·159 lines (137 loc) · 4.31 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
#!/bin/bash
# git-cloud installer
# https://github.com/jgorostegui/git-cloud
set -e
red() { echo -e "\033[0;31m$1\033[0m"; }
green() { echo -e "\033[0;32m$1\033[0m"; }
yellow() { echo -e "\033[1;33m$1\033[0m"; }
blue() { echo -e "\033[0;34m$1\033[0m"; }
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ask() {
local prompt="$1"
local default="${2:-n}"
local yn
if [ "$default" = "y" ]; then
read -r -p "$prompt [Y/n] " yn
yn="${yn:-y}"
else
read -r -p "$prompt [y/N] " yn
yn="${yn:-n}"
fi
[[ "$yn" =~ ^[Yy]$ ]]
}
detect_shell_rc() {
if [ -n "$ZSH_VERSION" ] || [[ "$SHELL" == *zsh* ]]; then
echo "$HOME/.zshrc"
else
echo "$HOME/.bashrc"
fi
}
echo ""
blue "╔═══════════════════════════════════════╗"
blue "║ git-cloud installer ║"
blue "╚═══════════════════════════════════════╝"
echo ""
# 1. Install script (always)
echo "Installing git-cloud to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
if [ -f "$SCRIPT_DIR/git-cloud" ]; then
cp "$SCRIPT_DIR/git-cloud" "$INSTALL_DIR/git-cloud"
else
echo "Downloading from GitHub..."
curl -fsSL https://raw.githubusercontent.com/jgorostegui/git-cloud/main/git-cloud \
-o "$INSTALL_DIR/git-cloud"
fi
chmod +x "$INSTALL_DIR/git-cloud"
green "✓ Installed to $INSTALL_DIR/git-cloud"
# Create .git-dirs (always)
mkdir -p "$HOME/.git-dirs"
green "✓ Created ~/.git-dirs"
echo ""
blue "── Optional configuration ──"
echo ""
SHELL_RC=$(detect_shell_rc)
# 2. PATH (only if needed)
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
if ask "Add $INSTALL_DIR to PATH in $SHELL_RC?"; then
{
echo ''
echo '# git-cloud: PATH'
# shellcheck disable=SC2016
echo 'export PATH="$HOME/.local/bin:$PATH"'
} >> "$SHELL_RC"
green "✓ Added PATH to $SHELL_RC"
else
yellow "⚠ Skipped. Add manually: export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
else
green "✓ PATH already configured"
fi
# 3. Completion
if ! grep -q '_git_cloud()' "$SHELL_RC" 2>/dev/null; then
echo ""
if ask "Add bash/zsh completion for git-cloud?"; then
cat >> "$SHELL_RC" << 'EOF'
# git-cloud: completion
_git_cloud() {
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ "$COMP_CWORD" -eq 1 ]; then
COMPREPLY=($(compgen -W "clone init setup sync migrate status version help" -- "$cur"))
fi
}
complete -F _git_cloud git-cloud
EOF
green "✓ Added completion to $SHELL_RC"
fi
fi
# 4. cd hook
if ! grep -q 'git-cloud: cd hook' "$SHELL_RC" 2>/dev/null; then
echo ""
echo "The cd hook shows a warning when you enter a synced folder without .git:"
echo " $ cd ~/GoogleDrive/dev/my-repo"
yellow " ⚠ Run 'git-cloud setup' to enable git here"
echo ""
if ask "Add cd hook?"; then
cat >> "$SHELL_RC" << 'EOF'
# git-cloud: cd hook
cd() {
builtin cd "$@" || return
if [[ -f .git-remote && ! -e .git ]]; then
echo -e "\033[1;33m⚠ Run 'git-cloud setup' to enable git here\033[0m"
fi
}
EOF
green "✓ Added cd hook to $SHELL_RC"
fi
fi
# 5. Global gitignore
echo ""
if ask "Configure global .gitignore to ignore .git-remote files?"; then
GITIGNORE_GLOBAL="$HOME/.gitignore_global"
if [ ! -f "$GITIGNORE_GLOBAL" ]; then
touch "$GITIGNORE_GLOBAL"
fi
if ! grep -q '.git-remote' "$GITIGNORE_GLOBAL" 2>/dev/null; then
echo ".git-remote" >> "$GITIGNORE_GLOBAL"
fi
git config --global core.excludesfile "$GITIGNORE_GLOBAL"
green "✓ Added .git-remote to $GITIGNORE_GLOBAL"
fi
# Done
echo ""
blue "═══════════════════════════════════════"
green "Installation complete!"
echo ""
echo "Next steps:"
echo ""
echo " 1. Reload shell: source $SHELL_RC"
echo ""
echo " 2. Add .git/ to cloud sync ignore rules:"
echo " Insync: Account Settings → Ignore Rules → .git/"
echo " Dropbox: echo '.git/' >> ~/Dropbox/rules.dropboxignore"
echo ""
echo " 3. Usage:"
echo " git-cloud clone <url> ~/GoogleDrive/dev/repo"
echo " git-cloud help"
echo ""