Skip to content

Commit

Permalink
new install method using pipx
Browse files Browse the repository at this point in the history
  • Loading branch information
ehammond committed Dec 9, 2024
1 parent bada0d4 commit fd57868
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 193 deletions.
168 changes: 53 additions & 115 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,177 +1,115 @@
# Installing abc (AI bash/zsh/tcsh Command)

This guide provides two methods for installing abc on your system: a modern Python package installation using pipx (recommended), and the traditional make-based installation.
This guide provides instructions for installing abc on your system using pipx.

## Prerequisites

- Linux or macOS
- Python 3.8 or higher
- bash 4.4+, zsh 5.0+, or tcsh 6.0+
- An API key for the Claude AI model from Anthropic
- bash 4.4 or higher, or zsh 5.0 or higher, or tcsh 6.0 or higher

## Modern Installation (Recommended)

The recommended way to install abc is using pipx, which automatically manages virtual environments for command-line tools:
## Installation

1. Install pipx if you haven't already:

```bash
python -m pip install --user pipx
python -m pipx ensurepath
```
# Linux (apt-based)
sudo apt install pipx
pipx ensurepath

2. Install abc directly from GitHub:
# macOS
brew install pipx
pipx ensurepath

```bash
pipx install git+https://github.com/alestic/abc.git
# Alternative: using pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
```

3. Complete install setup
2. Install abc:

```bash
pipx install git+https://github.com/alestic/abc.git
abc_setup
```

This will:
- Install shell integration scripts to ~/.local/share/abc
- Guide you through updating your shell configuration files
- Create backups of any modified files
- Provide instructions for API key configuration

For non-interactive environments or to skip all prompts:
Alternative:

```bash
abc_setup --yes
```

4. Follow the printed instructions to:

- Reload your shell configuration
- Set up your API key configuration

## Legacy Installation (Make-based)

The traditional make-based installation is still supported:

1. Clone the repository:

```
git clone https://github.com/alestic/abc.git
cd abc
pipx install .
abc_setup
```

2. Build dependencies and install in $HOME/.local/bin/

```
make build install
```

3. Add the appropriate shell integration to your shell configuration file:

For bash users, add to `~/.bashrc`:

```bash
source "$HOME/.local/bin/abc.sh"
```

For zsh users, add to `~/.zshrc`:

```zsh
source "$HOME/.local/bin/abc.sh"
```

For tcsh users, add to `~/.tcshrc`:

```tcsh
source "$HOME/.local/bin/abc.tcsh"
```

Then, reload your shell configuration:
This will:
- Install shell integration scripts
- Update your shell configuration
- Guide you through API key setup
- Create backups of any modified files

For bash:
3. Start a new terminal or reload your shell configuration:

```bash
# For bash
source ~/.bashrc
```

For zsh:

```zsh
# For zsh
source ~/.zshrc
```

For tcsh:

```tcsh
# For tcsh
source ~/.tcshrc
```

## Configuration

1. Create an Anthropic API key:
https://console.anthropic.com/settings/keys

2. Create a configuration file at `~/.abc.conf` with your API key:

```ini
[default]
api_key = your_api_key_here
```

## Verifying the Installation

To verify that abc is installed correctly, run:
To verify that abc is installed correctly:

```
```bash
abc --version
abc hi
```

This should display the version of abc.

## Updating

### Modern Installation

To update abc to the latest version when installed via pipx:
To update abc to the latest version:

```bash
pipx upgrade abc-cli
abc_setup # --yes to skip prompts
```

### Legacy Installation

To update abc when installed via make:

```bash
git pull
make build install
source ~/.bashrc # or ~/.zshrc for zsh, or ~/.tcshrc for tcsh
abc_setup
```

## Uninstalling

### Modern Installation

To uninstall abc when installed via pipx:
To remove abc from your system:

```bash
abc_setup --uninstall # --yes to skip prompts
abc_setup --uninstall
pipx uninstall abc-cli
```

The uninstall process will:
## Files and Locations

- Remove shell integration scripts
- Remove source lines from shell configuration files
- Create backups of any modified files
- Remove the ~/.local/share/abc directory
- Shell integration: `~/.local/share/abc/`
- Configuration: `~/.abc.conf`
- Shell configuration:
- bash: `~/.bashrc`
- zsh: `~/.zshrc`
- tcsh: `~/.tcshrc`

### Legacy Installation
## Troubleshooting

To uninstall abc when installed via make:
1. If you see "command not found: pipx" after installation:
- Run: `pipx ensurepath`
- Start a new terminal

```bash
make uninstall
```
2. If abc commands don't work after installation:
- Ensure your shell configuration was sourced
- Check that `~/.abc.conf` exists and contains your API key
- Verify the shell integration with `type abc`

Then remove the `source` line from your shell configuration file (`~/.bashrc`, `~/.zshrc`, or `~/.tcshrc`).
3. For other issues:
- Check the error message
- Verify Python version: `python3 --version`
- Ensure shell version meets requirements
53 changes: 14 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

# Variables
PYTHON := python3
INSTALL_DIR := $(HOME)/.local/bin
CONFIG_FILE := $(HOME)/.abc.conf
SHELL := /bin/bash
SHELL_SCRIPTS := abc.sh abc.tcsh

# Files
CONFIG_TEMPLATE := abc.conf.template
Expand All @@ -14,53 +12,30 @@ CONFIG_TEMPLATE := abc.conf.template
.DEFAULT_GOAL := help

# Phony targets
.PHONY: help build install uninstall clean config
.PHONY: help install uninstall clean config tree

help: ## Display this help message
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

build: ## Install dependencies and package using pipx
install-pipx:
@$(PYTHON) -m pip install --user --quiet pipx
@$(PYTHON) -m pipx ensurepath

install: install-pipx ## Install abc
@echo "Installing abc using pipx..."
$(PYTHON) -m pip install --user --quiet pipx
$(PYTHON) -m pipx ensurepath
$(PYTHON) -m pipx install --force .
@$(PYTHON) -m pipx install --force .
@abc_setup

install: build ## Install shell integration scripts
@echo "Installing shell integration scripts..."
mkdir -p $(INSTALL_DIR)
cp $(SHELL_SCRIPTS) $(INSTALL_DIR)/
@echo "abc has been installed"
@echo ""
@echo "Next steps:"
@echo "1. Add one of these lines to your shell configuration file:"
@echo " For bash/zsh:"
@echo " source \"$(INSTALL_DIR)/abc.sh\""
@echo " For tcsh:"
@echo " source \"$(INSTALL_DIR)/abc.tcsh\""
@echo "2. Create $(CONFIG_FILE) using $(CONFIG_TEMPLATE) as a template"
@echo "3. Reload your shell configuration"
setup: ## Re-create the config file
@abc_setup

uninstall: ## Uninstall abc
@echo "Uninstalling abc..."
$(PYTHON) -m pipx uninstall abc-cli
rm -f $(addprefix $(INSTALL_DIR)/,$(SHELL_SCRIPTS))
@echo "Removed abc-cli package and shell integration scripts"
@echo "Remember to remove the 'source' line from your shell configuration file"

clean: ## Remove generated files and caches
@echo "Cleaning up..."
find . -type f -name '*.pyc' -delete
find . -type d -name '__pycache__' -delete
rm -rf build/ dist/ *.egg-info/
@abc_setup --uninstall
@$(PYTHON) -m pipx uninstall abc-cli

config: ## Create a config file from the template
@if [ ! -f $(CONFIG_FILE) ]; then \
cp $(CONFIG_TEMPLATE) $(CONFIG_FILE); \
echo "Config file created at $(CONFIG_FILE)"; \
echo "Please edit it with your API key"; \
else \
echo "Config file already exists at $(CONFIG_FILE)"; \
fi
tree: ## Show a file tree
@git ls-files | tree --fromfile -a --filesfirst
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ $ abc 'count number of times each element shows in $PATH'
# (next command is generated by abc)
$ echo $PATH | tr ':' '\n' | sort | uniq -c | sort -rn
...
$ abc 'remove duplicate elements from $PATH, keeping the order, then save in PATH'
# (next command is generated by abc)
$ PATH=$(echo $PATH | tr ':' '\n' | awk '!seen[$0]++' | tr '\n' ':' | sed 's/:$//')
Expand Down Expand Up @@ -267,4 +268,4 @@ Prompt crafting by Eric Hammond

## Version

Current version: 2024-07-31
Current version: 2024-12-07
4 changes: 2 additions & 2 deletions abc_cli/abc_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import anthropic
import distro

VERSION: str = "# 2024-07-31"
VERSION: str = "# 2024-12-07"
PROGRAM_NAME: str = "abc"

# Config file
Expand All @@ -37,7 +37,7 @@
LOG_FORMAT_DATE: str = '%Y-%m-%d %H:%M:%S'

# LLM Constants
LLM_MODEL: str = "claude-3-5-sonnet-20240620"
LLM_MODEL: str = "claude-3-5-sonnet-20241022"
LLM_TEMPERATURE: float = 0.0
LLM_MAX_TOKENS: int = 1000

Expand Down
Loading

0 comments on commit fd57868

Please sign in to comment.