79 lines · 1.7 KB · executable
#!/usr/bin/env bash

set -euo pipefail

brewLocation="charmbracelet/tap/crush"
npmLocation="@charmland/crush"
local_bin="${HOME}/.bin/crush"
go_crush="${GOBIN:-${GOPATH:-$HOME/go}/bin}/crush"

is_linux=false
if [[ "$(uname -s)" == "Linux" ]]; then
	is_linux=true
fi

if [[ "$is_linux" == true ]]; then
	npm_check_cmd="sudo npm list -g $npmLocation"
	npm_uninstall_cmd="sudo npm uninstall -g $npmLocation"
else
	npm_check_cmd="npm list -g $npmLocation"
	npm_uninstall_cmd="npm uninstall -g $npmLocation"
fi

found=0

if command -v brew >/dev/null 2>&1 && brew list "$brewLocation" >/dev/null 2>&1; then
	echo "Found Crush via Homebrew"
	found=1
fi

if command -v npm >/dev/null 2>&1 && eval "$npm_check_cmd" >/dev/null 2>&1; then
	echo "Found Crush via NPM"
	found=1
fi

if [[ -x "$local_bin" ]]; then
	echo "Found local Crush binary at $local_bin"
	found=1
fi

if [[ -x "$go_crush" ]]; then