diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a389bad..cd56f52 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,6 +45,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Upgrade the outdated bash + run: brew install bash - name: Run setup approval tests run: test/approve_setup diff --git a/setup b/setup index 7cfafe6..9ad726c 100755 --- a/setup +++ b/setup @@ -1,53 +1,39 @@ #!/usr/bin/env bash - -fuzzy_cd_setup() { - patched="no" - - patch_file() { - file="$1" - if grep -q fuzzycd "$file"; then - echo "=== Skipping $file" - return - fi - - echo "=== Amending $file" - printf "source /usr/local/bin/fuzzycd\n" >>"$file" - patched="yes" - } - - download_script() { - echo "=== Saving fuzzycd to /usr/local/bin" - - sudo='' - if [[ $EUID -ne 0 ]]; then - sudo='sudo' - fi - - curl_command="curl -s https://raw.githubusercontent.com/DannyBen/fuzzycd/master/fuzzycd > /usr/local/bin/fuzzycd" - $sudo bash -c "$curl_command" - $sudo chmod 755 /usr/local/bin/fuzzycd - } - - patch_startup_files() { - patched="no" - echo "=== Searching for startup files" - [[ -f "$HOME/.zshrc" ]] && patch_file "$HOME/.zshrc" - [[ -f "$HOME/.bashrc" ]] && patch_file "$HOME/.bashrc" - } - - show_exit_message() { - if [[ $patched == "yes" ]]; then - echo "=== Done. You may need to source $file or restart your session" - else - echo "=== Setup is INCOMPLETE" - echo " Add 'source ~/.fuzzy-cd/fuzzy-cd' to your shell's initialization script" - exit 1 - fi - } - - download_script - patch_startup_files - show_exit_message -} - -fuzzy_cd_setup +set -euo pipefail + +# === Setup SSI === + +echo "Initializing installer..." +tmpdir="$(mktemp -d)" +trap 'rm -rf "$tmpdir"' EXIT +cd "$tmpdir" +export PATH="$tmpdir:$PATH" + +if command -v curl >/dev/null 2>&1; then + curl -fSsL https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi -o ssi +elif command -v wget >/dev/null 2>&1; then + wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi +else + echo "Error: please install wget or curl, then try again" >&2 + exit 1 +fi +chmod +x ssi + +# === Install === + +ssi log info "Installing fuzzycd" +ssi install bin https://raw.githubusercontent.com/DannyBen/fuzzycd/master/fuzzycd + +cat <<'EOF' | ssi install startup --shell bash --name fuzzycd.bashrc - +if command -v fuzzycd >/dev/null 2>&1; then + source "$(command -v fuzzycd)" +fi +EOF + +cat <<'EOF' | ssi install startup --shell zsh --name fuzzycd.zshrc - +if command -v fuzzycd >/dev/null 2>&1; then + source "$(command -v fuzzycd)" +fi +EOF + +ssi log info "fuzzycd -v : $(fuzzycd -v)" diff --git a/test/approve_setup b/test/approve_setup index 77e35a3..e7c3ba0 100755 --- a/test/approve_setup +++ b/test/approve_setup @@ -19,6 +19,7 @@ source /usr/local/bin/fuzzycd describe "cd is a function" [[ "$(type -t cd)" == "function" ]] || fail "Expected function got $(type -t cd)" -describe "~/.bashrc contains the source directive" - grep -q fuzzycd ~/.bashrc || fail "Expected to find source directive in ~/.bashrc" +describe "~/.bashrc.d contains the source directive file" + [[ -f ~/.bashrc.d/fuzzycd.bashrc ]] || fail "Expected to find source directive in ~/.bashrc" +../uninstall diff --git a/uninstall b/uninstall new file mode 100755 index 0000000..e3cd94f --- /dev/null +++ b/uninstall @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail + +# === Setup SSI === + +echo "Initializing installer..." +tmpdir="$(mktemp -d)" +trap 'rm -rf "$tmpdir"' EXIT +cd "$tmpdir" +export PATH="$tmpdir:$PATH" + +if command -v curl >/dev/null 2>&1; then + curl -fSsL https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi -o ssi +elif command -v wget >/dev/null 2>&1; then + wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi +else + echo "Error: please install wget or curl, then try again" >&2 + exit 1 +fi +chmod +x ssi + +# === Uninstall === + +ssi log info "Uninstalling fuzzycd" +ssi uninstall bin fuzzycd +ssi uninstall startup --shell bash fuzzycd.bashrc +ssi uninstall startup --shell zsh fuzzycd.zshrc