From d50de6a4aeda6d8031e5b32e669cbb4d849e042b Mon Sep 17 00:00:00 2001 From: AnnatarHe Date: Mon, 13 Apr 2026 01:27:00 +0800 Subject: [PATCH] feat(install): prefer Homebrew installation on macOS when available When macOS is detected and Homebrew is installed, attempt `brew install shelltime/tap/shelltime` before falling back to manual binary download. This provides better package management (upgrades, uninstalls) for macOS users while keeping the same hook/daemon setup workflow. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/test.yaml | 6 +++++- install.bash | 33 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6779ae2..e690409 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -60,5 +60,9 @@ jobs: fi [ -f ~/.shelltime/hooks/bash-preexec.sh ] || (echo "bash-preexec.sh not found in ~/.shelltime/hooks!" && exit 1) ls ~/.shelltime - ls ~/.shelltime/bin + if command -v brew >/dev/null 2>&1 && brew list shelltime >/dev/null 2>&1; then + which shelltime || (echo "shelltime not in PATH via Homebrew!" && exit 1) + else + ls ~/.shelltime/bin + fi ls ~/.shelltime/hooks diff --git a/install.bash b/install.bash index 40fb8c9..4b6d7f8 100644 --- a/install.bash +++ b/install.bash @@ -9,12 +9,28 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } +# Flag to track whether Homebrew installation was used +BREW_INSTALLED=false + # Check for required commands if ! command_exists curl; then echo "Error: curl is not installed." exit 1 fi +# On macOS, prefer Homebrew installation if brew is available +if [[ "$OS" == "Darwin" ]] && command_exists brew; then + echo "Homebrew detected on macOS. Attempting to install via brew..." + if brew install shelltime/tap/shelltime; then + BREW_INSTALLED=true + echo "Successfully installed shelltime via Homebrew." + else + echo "Homebrew installation failed. Falling back to manual installation..." + fi +fi + +if [ "$BREW_INSTALLED" = false ]; then + CLI_FILE_NAME="https://github.com/malamtime/cli/releases/latest/download/cli_" DAEMON_FILE_NAME="${CLI_FILE_NAME}daemon_" @@ -127,14 +143,6 @@ if [[ "$OS" == "Darwin" ]] || [[ "$OS" == "Linux" ]]; then # mv shelltime /c/Windows/System32/ fi -# Check if $HOME/.shelltime/daemon exists, create if not -if [ ! -d "$HOME/.shelltime/daemon" ]; then - mkdir -p "$HOME/.shelltime/daemon" - if [ $? -ne 0 ]; then - echo "Warning: Failed to create $HOME/.shelltime/daemon directory. Daemon functionality may be unavailable." - fi -fi - # Add $HOME/.shelltime/bin to user path if [[ "$OS" == "Darwin" ]] || [[ "$OS" == "Linux" ]]; then # For Zsh @@ -185,6 +193,15 @@ if [[ "$OS" == "MINGW64_NT" ]] || [[ "$OS" == "MSYS_NT" ]] || [[ "$OS" == "CYGWI echo "If you know where binaries should be installed on Windows, please open an issue: https://github.com/shelltime/cli" fi +fi # end of manual installation block + +# Check if $HOME/.shelltime/daemon exists, create if not +if [ ! -d "$HOME/.shelltime/daemon" ]; then + mkdir -p "$HOME/.shelltime/daemon" + if [ $? -ne 0 ]; then + echo "Warning: Failed to create $HOME/.shelltime/daemon directory. Daemon functionality may be unavailable." + fi +fi # STEP 2 # insert a preexec and postexec script to user configuration, including `zsh` and `fish`