Skip to content

Commit ec6348b

Browse files
authored
- Refactor setup script for a more polite autocomplete location
1 parent 31fc98d commit ec6348b

File tree

6 files changed

+89
-20
lines changed

6 files changed

+89
-20
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,38 @@ on:
66
jobs:
77
test:
88
name: Run test suite
9-
109
runs-on: ubuntu-latest
11-
1210
steps:
1311
- name: Checkout code
1412
uses: actions/checkout@v2
15-
1613
- name: Run shellcheck tests
17-
run: shellcheck rush
18-
14+
run: shellcheck rush setup
1915
- name: Build container for approval tests
2016
run: docker-compose build
21-
2217
- name: Run approval tests
2318
run: docker-compose run ci
2419

20+
ubuntu_setup:
21+
name: Setup on Ubuntu
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
- name: Run setup
27+
run: ./setup
28+
- name: Test setup artifacts
29+
run: test/setup_artifacts
30+
31+
macos_setup:
32+
name: Setup on macOS
33+
runs-on: macos-latest
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v2
37+
- name: Upgrade the outdated bash
38+
run: brew install bash
39+
- name: Run setup
40+
run: ./setup
41+
- name: Test setup artifacts
42+
run: test/setup_artifacts
43+

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Installation
4646

4747
### Installing using the setup script
4848

49-
This setup script simply downloads the rush executable to `/usr/local/bin/`.
49+
This setup script will download the rush executable to `/usr/local/bin/` and
50+
install an autocomplete script in the bash completions directory.
5051

5152
```shell
5253
$ bash <(curl -Ls get.dannyb.co/rush/setup)
@@ -60,9 +61,6 @@ Feel free to inspect the [setup script](setup) before running.
6061
Download the [rush](rush) script to `/usr/local/bin/` or anywhere in your
6162
`PATH`, and make it executable.
6263

63-
64-
### Installing auto-completion script
65-
6664
If you wish to have all package name auto-completed for all `rush` commands,
6765
add this line to your startup script (for example: `~/.bashrc`):
6866

rush

100644100755
File mode changed.

setup

100644100755
Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
#!/usr/bin/env bash
2-
echo "Downloading to /usr/local/bin/rush"
32

3+
# Figure out if we need sudo or not
4+
sudo=''
5+
if [[ $EUID -ne 0 ]]; then
6+
sudo='sudo'
7+
fi
8+
9+
# Download script from Github
10+
echo "=== Saving executable to /usr/local/bin/op"
411
curl_command="curl -s https://raw.githubusercontent.com/DannyBen/rush-cli/master/rush > /usr/local/bin/rush"
12+
$sudo bash -c "$curl_command"
13+
$sudo chmod a+x /usr/local/bin/rush
514

6-
if [[ $EUID -ne 0 ]]; then
7-
# not root, need sudo
8-
sudo bash -c "$curl_command"
9-
sudo chmod a+x /usr/local/bin/rush
15+
# Install completions
16+
if [[ -d "/usr/share/bash-completion/completions" ]]; then
17+
compdir="/usr/share/bash-completion/completions"
18+
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then
19+
compdir="/usr/local/etc/bash_completion.d"
20+
else
21+
compdir=''
22+
fi
23+
24+
if [[ -n $compdir ]]; then
25+
echo "=== Installing autocompletions to $compdir"
26+
echo "complete -W '$(rush list -s)' rush" | $sudo tee "${compdir}/rush" > /dev/null
1027
else
11-
# root
12-
bash -c "$curl_command"
13-
chmod a+x /usr/local/bin/rush
28+
echo "=== Completion script was not installed"
29+
echo " To install it manually add this to your startup script:"
30+
echo " complete -W '$(rush list -s)' rush"
1431
fi
1532

33+
# Verify
1634
if type rush > /dev/null; then
17-
echo "Done. Type 'rush --help' for more info."
35+
echo "=== Done. Type 'rush --help' for more info."
1836
else
19-
echo "Failed downloading."
37+
echo "=== Setup failed."
2038
exit 1
2139
fi

test/approve

100644100755
File mode changed.

test/setup_artifacts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
check_file() {
5+
file="$1"
6+
if [[ ! -f "$file" ]]; then
7+
echo "ERROR: File not found $file"
8+
exit 1
9+
fi
10+
}
11+
12+
get_comp_dir() {
13+
if [[ -d "/usr/share/bash-completion/completions" ]]; then
14+
echo "/usr/share/bash-completion/completions"
15+
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then
16+
echo "/usr/local/etc/bash_completion.d"
17+
else
18+
echo ''
19+
fi
20+
}
21+
22+
# Check that 'rush' is in its place
23+
check_file "/usr/local/bin/rush"
24+
25+
# Check that completions file is in place
26+
compdir="$(get_comp_dir)"
27+
if [[ -d "$compdir" ]]; then
28+
check_file "$compdir/rush"
29+
else
30+
echo "ERROR: Cannot find compdir, completions not installed"
31+
exit 1
32+
fi
33+
34+
echo "Setup artifacts are OK"

0 commit comments

Comments
 (0)