Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
90 changes: 38 additions & 52 deletions setup
Original file line number Diff line number Diff line change
@@ -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)"
5 changes: 3 additions & 2 deletions test/approve_setup
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions uninstall
Original file line number Diff line number Diff line change
@@ -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