|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# GitHub Copilot CLI Uninstallation Script |
| 5 | +# Usage: curl -fsSL https://gh.io/copilot-uninstall | bash |
| 6 | +# or: wget -qO- https://gh.io/copilot-uninstall | bash |
| 7 | +# Use | sudo bash to run as root and remove from /usr/local/bin |
| 8 | +# Export PREFIX to remove from $PREFIX/bin/ directory (default: /usr/local for |
| 9 | +# root, $HOME/.local for non-root), e.g., export PREFIX=$HOME/custom to remove |
| 10 | +# from $HOME/custom/bin |
| 11 | + |
| 12 | +echo "Uninstalling GitHub Copilot CLI..." |
| 13 | + |
| 14 | +# Detect platform |
| 15 | +case "$(uname -s || echo "")" in |
| 16 | + Darwin*|Linux*) ;; |
| 17 | + *) |
| 18 | + if command -v winget >/dev/null 2>&1; then |
| 19 | + echo "Windows detected. Uninstalling via winget..." |
| 20 | + winget uninstall GitHub.Copilot |
| 21 | + exit $? |
| 22 | + else |
| 23 | + echo "Error: Windows detected but winget not found. Please remove GitHub Copilot CLI using the package manager you installed it with." >&2 |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | + ;; |
| 27 | +esac |
| 28 | + |
| 29 | +# Check if running as root, fallback to non-root |
| 30 | +if [ "$(id -u 2>/dev/null || echo 1)" -eq 0 ]; then |
| 31 | + PREFIX="${PREFIX:-/usr/local}" |
| 32 | +else |
| 33 | + PREFIX="${PREFIX:-$HOME/.local}" |
| 34 | +fi |
| 35 | +INSTALL_DIR="$PREFIX/bin" |
| 36 | +TARGET="$INSTALL_DIR/copilot" |
| 37 | + |
| 38 | +if [ ! -e "$TARGET" ]; then |
| 39 | + echo "Notice: No copilot binary found at $TARGET." |
| 40 | + |
| 41 | + if command -v copilot >/dev/null 2>&1; then |
| 42 | + FOUND_PATH="$(command -v copilot)" |
| 43 | + echo "Another copilot binary is still available at $FOUND_PATH." |
| 44 | + echo "If you installed it with Homebrew, npm, or another package manager, uninstall it with that tool." |
| 45 | + fi |
| 46 | + |
| 47 | + exit 0 |
| 48 | +fi |
| 49 | + |
| 50 | +if [ ! -w "$TARGET" ] && [ "$(id -u 2>/dev/null || echo 1)" -ne 0 ]; then |
| 51 | + echo "Error: Could not remove $TARGET. You may not have write permissions." >&2 |
| 52 | + echo "Try running this script with sudo or set PREFIX to the installation prefix used previously." >&2 |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | + |
| 56 | +rm -f "$TARGET" |
| 57 | +echo "✓ Removed $TARGET" |
| 58 | + |
| 59 | +if [ -d "$INSTALL_DIR" ] && [ -z "$(ls -A "$INSTALL_DIR" 2>/dev/null)" ]; then |
| 60 | + rmdir "$INSTALL_DIR" 2>/dev/null || true |
| 61 | +fi |
| 62 | + |
| 63 | +echo "" |
| 64 | +echo "Uninstall complete." |
| 65 | +echo "If you previously added $INSTALL_DIR to your PATH, you can remove that entry from your shell profile manually." |
0 commit comments