-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
274e23c
commit ec05081
Showing
2 changed files
with
39 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,47 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Function to print error messages in red | ||
error() { | ||
echo -e "\033[0;31merror:\033[0m $1" >&2 | ||
exit 1 | ||
} | ||
# [Initialize color codes and helper functions as in bun.sh] | ||
|
||
# Function to print information in dim color | ||
info() { | ||
echo -e "\033[0;2m$1\033[0m" | ||
} | ||
# Check for bun | ||
command -v bun >/dev/null || | ||
error 'bun is required to run aitdd. Please install bun first.' | ||
|
||
# Function to install bun | ||
install_bun() { | ||
info "Installing bun..." | ||
curl -fsSL https://bun.sh/install | bash | ||
} | ||
# Define the GitHub repository URL | ||
github_repo="https://github.com/di-sukharev/AI-TDD" | ||
|
||
# Check for bun and install if not present | ||
if ! command -v bun &> /dev/null; then | ||
install_bun | ||
else | ||
info "bun is already installed. Good. Continue." | ||
fi | ||
# Construct the download URL for your CLI | ||
# Modify this URL to point to the specific release or directory containing cli.ts | ||
aitdd_uri="$github_repo/releases/latest/download/out.zip" | ||
|
||
# Define installation directory | ||
BIN_DIR="$HOME/.local/bin" | ||
mkdir -p "$BIN_DIR" | ||
# Define the installation directory | ||
install_dir=${HOME}/.aitdd | ||
bin_dir=$install_dir/bin | ||
exe=$bin_dir/aitdd | ||
|
||
# Create a symbolic link to the CLI tool | ||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) | ||
CLI_FILE="$SCRIPT_DIR/cli.ts" | ||
ln -sf "$CLI_FILE" "$BIN_DIR/aitdd" | ||
# Create the installation directory if it doesn't exist | ||
mkdir -p "$bin_dir" || | ||
error "Failed to create install directory \"$bin_dir\"" | ||
|
||
# Detect the shell and update the corresponding configuration file | ||
SHELL_NAME=$(basename "$SHELL") | ||
case "$SHELL_NAME" in | ||
bash) | ||
SHELL_CONFIG="$HOME/.bashrc" | ||
;; | ||
zsh) | ||
SHELL_CONFIG="$HOME/.zshrc" | ||
;; | ||
fish) | ||
SHELL_CONFIG="$HOME/.config/fish/config.fish" | ||
;; | ||
*) | ||
SHELL_CONFIG="" | ||
;; | ||
esac | ||
# Download and extract your CLI files | ||
curl --fail --location --output "$exe.zip" "$aitdd_uri" || | ||
error "Failed to download aitdd from \"$aitdd_uri\"" | ||
|
||
# Update PATH in the user's shell configuration file | ||
if [[ -n $SHELL_CONFIG && -w $SHELL_CONFIG ]]; then | ||
if ! grep -q "$BIN_DIR" "$SHELL_CONFIG"; then | ||
if [[ "$SHELL_NAME" == "fish" ]]; then | ||
echo "set -gx PATH \"$BIN_DIR\" \$PATH" >> "$SHELL_CONFIG" | ||
else | ||
echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$SHELL_CONFIG" | ||
fi | ||
info "Added $BIN_DIR to PATH in $SHELL_CONFIG" | ||
fi | ||
else | ||
info "Could not update PATH automatically. Please add $BIN_DIR to your PATH manually." | ||
fi | ||
unzip -oqd "$install_dir" "$exe.zip" || | ||
error 'Failed to extract aitdd' | ||
|
||
# Refresh environment (this won't affect the parent shell) | ||
export PATH="$BIN_DIR:$PATH" | ||
# Create the aitdd wrapper command | ||
cat <<EOF >"$exe" | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
bun $install_dir/src/cli.ts "\$@" | ||
EOF | ||
|
||
# Check if the tool is available in the PATH | ||
if command -v aitdd &> /dev/null; then | ||
info "aitdd tool installed successfully and is available in your PATH." | ||
else | ||
info "Installation complete, but the aitdd tool is not in your PATH. Please restart your shell or source your shell configuration file." | ||
fi | ||
# Make the wrapper executable | ||
chmod +x "$exe" || | ||
error 'Failed to set permissions on aitdd executable' | ||
|
||
# [Optional: Provide instructions for adding $bin_dir to PATH] | ||
|
||
# Success message | ||
success "aitdd was installed successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters