diff --git a/README.md b/README.md index 98d8daa..a338b49 100644 --- a/README.md +++ b/README.md @@ -85,10 +85,10 @@ bun link # optional global arrowcode / ac ### Update -To update ArrowCode while preserving any local modifications you have made: +To instantly update ArrowCode from any directory, keeping your local changes preserved: ```bash -./update.sh +curl -fsSL https://raw.githubusercontent.com/Chintanpatel24/arrowcode/main/update.sh | bash ``` ### Setup API key diff --git a/update.sh b/update.sh index ea0a351..9571652 100755 --- a/update.sh +++ b/update.sh @@ -13,8 +13,30 @@ log() { printf '%s==>%s %s\n' "$CYN" "$RST" "$*"; } ok() { printf '%s[ok]%s %s\n' "$GRN" "$RST" "$*"; } err() { printf '%s[err]%s %s\n' "$RED" "$RST" "$*" >&2; } -# Find ArrowCode base directory -DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# Find ArrowCode base directory dynamically (even if piped via stdin) +if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then + DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +else + # fallback to global/local shared locations if piped via stdin + DIR="${ARROWCODE_DIR:-$HOME/.local/share/arrowcode}" +fi + +if [ ! -d "$DIR" ] || [ ! -f "$DIR/package.json" ]; then + # Try to find base from command line 'arrowcode' binary symlink or standard home folder + if command -v arrowcode >/dev/null 2>&1; then + BIN_PATH=$(which arrowcode) + if [ -h "$BIN_PATH" ]; then + REAL_BIN=$(readlink "$BIN_PATH") + DIR="$(cd "$(dirname "$REAL_BIN")/.." && pwd)" + fi + fi +fi + +if [ ! -d "$DIR" ] || [ ! -f "$DIR/package.json" ]; then + err "Could not find ArrowCode installation directory. Please run the installer first or set ARROWCODE_DIR." + exit 1 +fi + cd "$DIR" log "Updating ArrowCode at $DIR..."