Skip to content

Commit 72a40be

Browse files
authored
Merge pull request #21 from DannyBen/update/setup
Update setup/uninstall
2 parents 4a88312 + fa75c74 commit 72a40be

File tree

4 files changed

+70
-54
lines changed

4 files changed

+70
-54
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
steps:
4646
- name: Checkout code
4747
uses: actions/checkout@v4
48+
- name: Upgrade the outdated bash
49+
run: brew install bash
4850
- name: Run setup approval tests
4951
run: test/approve_setup
5052

setup

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
11
#!/usr/bin/env bash
2-
3-
fuzzy_cd_setup() {
4-
patched="no"
5-
6-
patch_file() {
7-
file="$1"
8-
if grep -q fuzzycd "$file"; then
9-
echo "=== Skipping $file"
10-
return
11-
fi
12-
13-
echo "=== Amending $file"
14-
printf "source /usr/local/bin/fuzzycd\n" >>"$file"
15-
patched="yes"
16-
}
17-
18-
download_script() {
19-
echo "=== Saving fuzzycd to /usr/local/bin"
20-
21-
sudo=''
22-
if [[ $EUID -ne 0 ]]; then
23-
sudo='sudo'
24-
fi
25-
26-
curl_command="curl -s https://raw.githubusercontent.com/DannyBen/fuzzycd/master/fuzzycd > /usr/local/bin/fuzzycd"
27-
$sudo bash -c "$curl_command"
28-
$sudo chmod 755 /usr/local/bin/fuzzycd
29-
}
30-
31-
patch_startup_files() {
32-
patched="no"
33-
echo "=== Searching for startup files"
34-
[[ -f "$HOME/.zshrc" ]] && patch_file "$HOME/.zshrc"
35-
[[ -f "$HOME/.bashrc" ]] && patch_file "$HOME/.bashrc"
36-
}
37-
38-
show_exit_message() {
39-
if [[ $patched == "yes" ]]; then
40-
echo "=== Done. You may need to source $file or restart your session"
41-
else
42-
echo "=== Setup is INCOMPLETE"
43-
echo " Add 'source ~/.fuzzy-cd/fuzzy-cd' to your shell's initialization script"
44-
exit 1
45-
fi
46-
}
47-
48-
download_script
49-
patch_startup_files
50-
show_exit_message
51-
}
52-
53-
fuzzy_cd_setup
2+
set -euo pipefail
3+
4+
# === Setup SSI ===
5+
6+
echo "Initializing installer..."
7+
tmpdir="$(mktemp -d)"
8+
trap 'rm -rf "$tmpdir"' EXIT
9+
cd "$tmpdir"
10+
export PATH="$tmpdir:$PATH"
11+
12+
if command -v curl >/dev/null 2>&1; then
13+
curl -fSsL https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi -o ssi
14+
elif command -v wget >/dev/null 2>&1; then
15+
wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi
16+
else
17+
echo "Error: please install wget or curl, then try again" >&2
18+
exit 1
19+
fi
20+
chmod +x ssi
21+
22+
# === Install ===
23+
24+
ssi log info "Installing fuzzycd"
25+
ssi install bin https://raw.githubusercontent.com/DannyBen/fuzzycd/master/fuzzycd
26+
27+
cat <<'EOF' | ssi install startup --shell bash --name fuzzycd.bashrc -
28+
if command -v fuzzycd >/dev/null 2>&1; then
29+
source "$(command -v fuzzycd)"
30+
fi
31+
EOF
32+
33+
cat <<'EOF' | ssi install startup --shell zsh --name fuzzycd.zshrc -
34+
if command -v fuzzycd >/dev/null 2>&1; then
35+
source "$(command -v fuzzycd)"
36+
fi
37+
EOF
38+
39+
ssi log info "fuzzycd -v : $(fuzzycd -v)"

test/approve_setup

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ source /usr/local/bin/fuzzycd
1919
describe "cd is a function"
2020
[[ "$(type -t cd)" == "function" ]] || fail "Expected function got $(type -t cd)"
2121

22-
describe "~/.bashrc contains the source directive"
23-
grep -q fuzzycd ~/.bashrc || fail "Expected to find source directive in ~/.bashrc"
22+
describe "~/.bashrc.d contains the source directive file"
23+
[[ -f ~/.bashrc.d/fuzzycd.bashrc ]] || fail "Expected to find source directive in ~/.bashrc"
2424

25+
../uninstall

uninstall

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# === Setup SSI ===
5+
6+
echo "Initializing installer..."
7+
tmpdir="$(mktemp -d)"
8+
trap 'rm -rf "$tmpdir"' EXIT
9+
cd "$tmpdir"
10+
export PATH="$tmpdir:$PATH"
11+
12+
if command -v curl >/dev/null 2>&1; then
13+
curl -fSsL https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi -o ssi
14+
elif command -v wget >/dev/null 2>&1; then
15+
wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v0.1.4/ssi
16+
else
17+
echo "Error: please install wget or curl, then try again" >&2
18+
exit 1
19+
fi
20+
chmod +x ssi
21+
22+
# === Uninstall ===
23+
24+
ssi log info "Uninstalling fuzzycd"
25+
ssi uninstall bin fuzzycd
26+
ssi uninstall startup --shell bash fuzzycd.bashrc
27+
ssi uninstall startup --shell zsh fuzzycd.zshrc

0 commit comments

Comments
 (0)