-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·250 lines (215 loc) · 7.06 KB
/
install.sh
File metadata and controls
executable file
·250 lines (215 loc) · 7.06 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
#!/bin/bash
set -euo pipefail
# flow-cli installer
# ZSH workflow tools for ADHD brains
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/Data-Wise/flow-cli/main/install.sh | bash
#
# Options:
# INSTALL_METHOD=antidote|zinit|omz|manual (default: auto-detect)
# FLOW_INSTALL_DIR=/custom/path (default: ~/.flow-cli)
# FLOW_VERSION=v4.5.1 (default: latest)
#
# Examples:
# # Install latest
# curl -fsSL .../install.sh | bash
#
# # Install specific version
# FLOW_VERSION=v4.5.1 curl -fsSL .../install.sh | bash
#
# # Install with manual method
# INSTALL_METHOD=manual curl -fsSL .../install.sh | bash
REPO="Data-Wise/flow-cli"
PLUGIN_NAME="flow-cli"
INSTALL_DIR="${FLOW_INSTALL_DIR:-$HOME/.flow-cli}"
VERSION="${FLOW_VERSION:-}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e "${BLUE}==>${NC} $1"; }
success() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}!${NC} $1"; }
error() { echo -e "${RED}✗${NC} $1" >&2; exit 1; }
# Detect ZSH plugin manager
detect_plugin_manager() {
if [[ -n "${INSTALL_METHOD:-}" ]]; then
echo "$INSTALL_METHOD"
return
fi
# Check for antidote (look for plugins file or command)
if [[ -f "${ZDOTDIR:-$HOME}/.zsh_plugins.txt" ]] || command -v antidote &>/dev/null; then
echo "antidote"
# Check for zinit
elif [[ -d "$HOME/.zinit" ]] || [[ -d "${ZINIT_HOME:-$HOME/.zinit}" ]] || [[ -d "$HOME/.local/share/zinit" ]]; then
echo "zinit"
# Check for oh-my-zsh
elif [[ -d "$HOME/.oh-my-zsh" ]] || [[ -n "${ZSH:-}" && -d "${ZSH:-}" ]]; then
echo "omz"
# Fall back to manual
else
echo "manual"
fi
}
# Install with antidote
install_antidote() {
info "Installing with antidote..."
local plugins_file="${ZDOTDIR:-$HOME}/.zsh_plugins.txt"
# Create plugins file if it doesn't exist
if [[ ! -f "$plugins_file" ]]; then
warn "Creating $plugins_file"
touch "$plugins_file"
fi
# Build plugin entry (with optional version tag)
local plugin_entry="$REPO"
if [[ -n "$VERSION" ]]; then
plugin_entry="${REPO}@${VERSION}"
info "Pinning to version $VERSION"
fi
if ! grep -q "$REPO" "$plugins_file" 2>/dev/null; then
echo "" >> "$plugins_file"
echo "# flow-cli - ZSH workflow tools" >> "$plugins_file"
echo "$plugin_entry" >> "$plugins_file"
success "Added $plugin_entry to $plugins_file"
else
success "Already in $plugins_file"
fi
warn "Run 'antidote update' and restart your shell to activate"
}
# Install with zinit
install_zinit() {
info "Installing with zinit..."
local zshrc="${ZDOTDIR:-$HOME}/.zshrc"
# Build zinit command (with optional version ice)
local zinit_cmd
if [[ -n "$VERSION" ]]; then
zinit_cmd="zinit ice ver\"$VERSION\"; zinit light $REPO"
info "Pinning to version $VERSION"
else
zinit_cmd="zinit light $REPO"
fi
if ! grep -q "zinit.*$PLUGIN_NAME" "$zshrc" 2>/dev/null; then
echo "" >> "$zshrc"
echo "# flow-cli - ZSH workflow tools" >> "$zshrc"
echo "$zinit_cmd" >> "$zshrc"
success "Added zinit configuration to $zshrc"
else
success "Already configured in $zshrc"
fi
warn "Restart your shell to activate"
}
# Install with oh-my-zsh
install_omz() {
info "Installing with oh-my-zsh..."
local custom_dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
local plugin_dir="$custom_dir/$PLUGIN_NAME"
mkdir -p "$custom_dir"
if [[ -d "$plugin_dir" ]]; then
info "Updating existing installation..."
git -C "$plugin_dir" pull --quiet
success "Updated $plugin_dir"
else
info "Cloning repository..."
git clone --quiet "https://github.com/$REPO.git" "$plugin_dir"
success "Installed to $plugin_dir"
fi
# Checkout specific version if requested
if [[ -n "$VERSION" ]]; then
info "Checking out version $VERSION..."
git -C "$plugin_dir" checkout --quiet "$VERSION" || error "Version $VERSION not found"
success "Using version $VERSION"
fi
# Check if plugin is in plugins list
local zshrc="${ZDOTDIR:-$HOME}/.zshrc"
if grep -q "plugins=.*$PLUGIN_NAME" "$zshrc" 2>/dev/null; then
success "Plugin already in plugins list"
else
warn "Add '$PLUGIN_NAME' to plugins=(...) in $zshrc"
echo ""
echo " Example:"
echo " plugins=(git $PLUGIN_NAME)"
fi
}
# Manual installation (fallback)
install_manual() {
info "Installing manually to $INSTALL_DIR..."
if [[ -d "$INSTALL_DIR" ]]; then
info "Updating existing installation..."
git -C "$INSTALL_DIR" pull --quiet
success "Updated $INSTALL_DIR"
else
info "Cloning repository..."
git clone --quiet "https://github.com/$REPO.git" "$INSTALL_DIR"
success "Installed to $INSTALL_DIR"
fi
# Checkout specific version if requested
if [[ -n "$VERSION" ]]; then
info "Checking out version $VERSION..."
git -C "$INSTALL_DIR" checkout --quiet "$VERSION" || error "Version $VERSION not found"
success "Using version $VERSION"
fi
local zshrc="${ZDOTDIR:-$HOME}/.zshrc"
local source_line="source $INSTALL_DIR/flow.plugin.zsh"
if ! grep -q "flow.plugin.zsh" "$zshrc" 2>/dev/null; then
echo "" >> "$zshrc"
echo "# flow-cli - ZSH workflow tools" >> "$zshrc"
echo "$source_line" >> "$zshrc"
success "Added source line to $zshrc"
else
success "Already sourced in $zshrc"
fi
warn "Restart your shell to activate"
}
# Print quick start guide
print_quickstart() {
echo ""
echo -e "${BOLD}Quick Start${NC}"
echo ""
echo " 1. Restart your shell or run:"
echo " source ~/.zshrc"
echo ""
echo " 2. Verify installation:"
echo " flow doctor"
echo ""
echo " 3. Start working:"
echo " work my-project # Start session"
echo " win \"Did something\" # Log a win"
echo " finish # End session"
echo ""
echo -e "${BLUE}Documentation:${NC} https://data-wise.github.io/flow-cli/"
echo ""
}
# Main installation flow
main() {
echo ""
echo -e "${BOLD}flow-cli installer${NC}"
echo "ZSH workflow tools for ADHD brains"
echo ""
# Check for ZSH
if ! command -v zsh &>/dev/null; then
error "ZSH is required but not installed. Install ZSH first."
fi
# Check for git
if ! command -v git &>/dev/null; then
error "Git is required but not installed. Install Git first."
fi
local method
method=$(detect_plugin_manager)
info "Detected plugin manager: ${BOLD}${method}${NC}"
echo ""
case "$method" in
antidote) install_antidote ;;
zinit) install_zinit ;;
omz) install_omz ;;
manual) install_manual ;;
*) error "Unknown install method: $method" ;;
esac
echo ""
success "flow-cli installation complete!"
print_quickstart
}
main "$@"