-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·220 lines (186 loc) · 8.51 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·220 lines (186 loc) · 8.51 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
#!/usr/bin/env bash
# install.sh — build and install TaskFlow
set -euo pipefail
BINARY_NAME="taskflow"
REQUIRED_RUST_MINOR="87" # 1.87
# ── Flags ──────────────────────────────────────────────────────────────────────
SYSTEM_INSTALL=false
INSTALL_COMPLETIONS="" # "" = auto-detect, "yes" = force, "no" = skip
UNINSTALL=false
usage() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Build and install TaskFlow.
Options:
--system Install to /usr/local/bin (requires sudo)
--completions Install shell completions (auto-detects shell)
--no-completions Skip shell completion install
--uninstall Remove binary and completions from install location
--help Show this help
Default (no flags): install binary to ~/.local/bin
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--system) SYSTEM_INSTALL=true ;;
--completions) INSTALL_COMPLETIONS="yes" ;;
--no-completions) INSTALL_COMPLETIONS="no" ;;
--uninstall) UNINSTALL=true ;;
--help|-h) usage; exit 0 ;;
*) echo "Unknown option: $1"; usage; exit 1 ;;
esac
shift
done
# ── Paths ──────────────────────────────────────────────────────────────────────
if $SYSTEM_INSTALL; then
BIN_DIR="/usr/local/bin"
BASH_COMP_DIR="/etc/bash_completion.d"
ZSH_COMP_DIR="/usr/local/share/zsh/site-functions"
FISH_COMP_DIR="/usr/share/fish/completions"
INSTALL_CMD="sudo"
else
BIN_DIR="${HOME}/.local/bin"
BASH_COMP_DIR="${HOME}/.local/share/bash-completion/completions"
ZSH_COMP_DIR="${HOME}/.zfunc"
FISH_COMP_DIR="${HOME}/.config/fish/completions"
INSTALL_CMD=""
fi
BINARY_PATH="${BIN_DIR}/${BINARY_NAME}"
# ── Helpers ────────────────────────────────────────────────────────────────────
info() { echo " [info] $*"; }
success() { echo " [ok] $*"; }
warn() { echo " [warn] $*" >&2; }
error() { echo " [err] $*" >&2; exit 1; }
run_install() {
if [[ -n "$INSTALL_CMD" ]]; then
sudo "$@"
else
"$@"
fi
}
# ── Uninstall ──────────────────────────────────────────────────────────────────
if $UNINSTALL; then
echo "Uninstalling TaskFlow..."
removed=0
for path in \
"${BINARY_PATH}" \
"${BASH_COMP_DIR}/${BINARY_NAME}" \
"${ZSH_COMP_DIR}/_${BINARY_NAME}" \
"${FISH_COMP_DIR}/${BINARY_NAME}.fish"
do
if [[ -e "$path" ]]; then
run_install rm -f "$path"
success "Removed $path"
removed=$((removed + 1))
fi
done
if [[ $removed -eq 0 ]]; then
info "Nothing to remove — TaskFlow does not appear to be installed."
else
success "Uninstall complete."
fi
exit 0
fi
# ── Prerequisites ──────────────────────────────────────────────────────────────
echo "Checking prerequisites..."
if ! command -v cargo &>/dev/null; then
error "cargo not found. Install Rust from https://rustup.rs and try again."
fi
if ! command -v rustc &>/dev/null; then
error "rustc not found. Install Rust from https://rustup.rs and try again."
fi
RUST_VERSION_FULL=$(rustc --version)
# Extract "1.XX" from e.g. "rustc 1.87.0 (xxxxxx 2025-05-22)"
RUST_MINOR=$(echo "$RUST_VERSION_FULL" | grep -oP '(?<=1\.)\d+' | head -1)
if [[ -z "$RUST_MINOR" ]]; then
warn "Could not parse Rust version from: $RUST_VERSION_FULL"
warn "Continuing anyway — install may fail if Rust is too old."
elif [[ "$RUST_MINOR" -lt "$REQUIRED_RUST_MINOR" ]]; then
error "Rust 1.${REQUIRED_RUST_MINOR} or later required (found $RUST_VERSION_FULL). Run: rustup update"
fi
success "Rust: $RUST_VERSION_FULL"
# ── Build ──────────────────────────────────────────────────────────────────────
echo ""
echo "Building TaskFlow (release)..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
cargo build --release
success "Build complete: target/release/${BINARY_NAME}"
# ── Install binary ─────────────────────────────────────────────────────────────
echo ""
echo "Installing binary..."
run_install mkdir -p "$BIN_DIR"
run_install cp "target/release/${BINARY_NAME}" "$BINARY_PATH"
run_install chmod 755 "$BINARY_PATH"
success "Installed: $BINARY_PATH"
# PATH warning
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then
warn "${BIN_DIR} is not in \$PATH."
warn "Add this to your shell rc file:"
warn " export PATH=\"${BIN_DIR}:\$PATH\""
fi
# ── Shell completions ──────────────────────────────────────────────────────────
install_bash_completion() {
run_install mkdir -p "$BASH_COMP_DIR"
"$BINARY_PATH" completion bash | run_install tee "${BASH_COMP_DIR}/${BINARY_NAME}" >/dev/null
success "Bash completion: ${BASH_COMP_DIR}/${BINARY_NAME}"
info "Reload your shell or run:"
info " source ${BASH_COMP_DIR}/${BINARY_NAME}"
}
install_zsh_completion() {
run_install mkdir -p "$ZSH_COMP_DIR"
"$BINARY_PATH" completion zsh | run_install tee "${ZSH_COMP_DIR}/_${BINARY_NAME}" >/dev/null
success "Zsh completion: ${ZSH_COMP_DIR}/_${BINARY_NAME}"
if ! grep -q "fpath.*${ZSH_COMP_DIR}" "${ZDOTDIR:-$HOME}/.zshrc" 2>/dev/null; then
info "Add this to ~/.zshrc if ${ZSH_COMP_DIR} is not already in fpath:"
info " fpath=(${ZSH_COMP_DIR} \$fpath)"
info " autoload -Uz compinit && compinit"
fi
}
install_fish_completion() {
run_install mkdir -p "$FISH_COMP_DIR"
"$BINARY_PATH" completion fish | run_install tee "${FISH_COMP_DIR}/${BINARY_NAME}.fish" >/dev/null
success "Fish completion: ${FISH_COMP_DIR}/${BINARY_NAME}.fish"
info "Fish will pick up completions automatically on next launch."
}
echo ""
if [[ "$INSTALL_COMPLETIONS" == "no" ]]; then
info "Skipping shell completions (--no-completions)."
else
if [[ "$INSTALL_COMPLETIONS" == "yes" ]]; then
# Force: detect shell and install
detect_and_install=true
else
# Auto-detect: only install if shell is known
detect_and_install=true
fi
if $detect_and_install; then
echo "Installing shell completions..."
case "${SHELL:-}" in
*/bash) install_bash_completion ;;
*/zsh) install_zsh_completion ;;
*/fish) install_fish_completion ;;
*)
if [[ "$INSTALL_COMPLETIONS" == "yes" ]]; then
warn "Could not detect shell from \$SHELL='${SHELL:-}'."
warn "Run one of:"
warn " bash install.sh --completions (from a bash session)"
warn " zsh install.sh --completions (from a zsh session)"
warn " fish install.sh --completions (from a fish session)"
else
info "Shell not detected; skipping completions."
info "Re-run with --completions to install them."
fi
;;
esac
fi
fi
# ── Summary ────────────────────────────────────────────────────────────────────
echo ""
echo "────────────────────────────────────────"
echo " TaskFlow installed successfully"
echo "────────────────────────────────────────"
echo " Binary : $BINARY_PATH"
echo ""
echo " Run 'taskflow --help' to get started."
echo "────────────────────────────────────────"