chimney (nix old logs)
[webi-installers/.git] / rg / rg.bash
1 # title: Ripgrep
2 # homepage: https://github.com/BurntSushi/ripgrep
3 # tagline: a modern drop-in grep replacement
4 # alias: rg
5 # description: |
6 #   `rg` is a drop-in replacement for `grep`, that respects `.gitignore` and `.ignore`, has all of the sensible default options you want (colors, numbers, etc) turned on by default, is written in Rust, and simply outperforms grep in every imaginable way. R.I.P. grep.
7 # examples: |
8 #
9 #   ```bash
10 #   rg <search-term> # searches recursively, ignoing .git, node_modules, etc
11 #   ```
12 #
13 #   ```bash
14 #   rg 'function doStuff'
15 #   ```
16 #
17 #   ```bash
18 #   rg 'doStuff\(.*\)'
19 #   ```
20
21 set -e
22 set -u
23
24 ###################
25 # Install ripgrep #
26 ###################
27
28 new_rg="${HOME}/.local/bin/rg"
29
30 # Test for existing version
31 set +e
32 cur_rg="$(command -v rg)"
33 set -e
34 if [ -n "$cur_rg" ]; then
35   cur_ver=$(rg --version | head -n 1 | cut -d ' ' -f 2)
36   if [ "$cur_ver" == "$WEBI_VERSION" ]; then
37     echo "ripgrep v$WEBI_VERSION already installed at $cur_rg"
38     exit 0
39   elif [ "$cur_rg" != "$new_rg" ]; then
40     echo "WARN: possible conflict with ripgrep v$WEBI_VERSION at $cur_rg"
41   fi
42 fi
43
44 # Note: this file is `source`d by the true installer and hence will have the webi functions
45
46 # because we created releases.js we can use webi_download()
47 # downloads ripgrep to ~/Downloads
48 webi_download
49
50 # because this is tar or zip, we can webi_extract()
51 # extracts to the WEBI_TMP directory, raw (no --strip-prefix)
52 webi_extract
53
54 pushd "$WEBI_TMP" 2>&1 >/dev/null
55         echo Installing ripgrep v${WEBI_VERSION} as "$new_rg"
56         mv ./ripgrep-*/rg "$HOME/.local/bin/"
57 popd 2>&1 >/dev/null
58
59 ###################
60 #   Update PATH   #
61 ###################
62
63 # TODO get better output from pathman / output the path to add as return to webi bootstrap
64 webi_path_add "$HOME/.local/bin"
65
66 echo "Installed 'rg'"
67 echo ""