add ripgrep

This commit is contained in:
AJ ONeal
2020-05-02 20:43:53 +00:00
parent f127374292
commit 260a2f1a8a
5 changed files with 170 additions and 18 deletions

View File

@@ -2,33 +2,44 @@
// this may need customizations between packages
const osMap = {
macos: /\b(mac|darwin|iPhone|iOS|iPad)/i,
macos: /\b(apple|mac|darwin|iPhone|iOS|iPad)/i,
linux: /\b(linux)/i,
win: /\b(win|microsoft|msft)/i,
sunos: /\b(sun)/i,
aix: /\b(aix)/i
};
const archMap = {
amd64: /(amd64|x64|[_\-]64)/i,
x86: /\b(x86)(?![_\-]64)/i,
// evaluation order matters
// (i.e. otherwise x86 and x64 can cross match)
var archArr = [
'amd64', // first and most likely match
'arm64',
'x86',
'ppc64le',
'ppc64',
'armv7l',
'armv6l',
's390x'
];
var archMap = {
amd64: /(amd.?64|x64|[_\-]64)/i,
x86: /(86)\b/i,
ppc64le: /\b(ppc64le)/i,
ppc64: /\b(ppc64)\b/i,
i686: /\b(i686)\b/i,
arm64: /\b(arm64|arm)/i,
armv7l: /\b(armv?7l)/i,
armv6l: /\b(armv?6l)/i,
s390x: /\b(s390x)/i
};
const fileExtMap = {
var fileExtMap = {
deb: /\.deb$/i,
pkg: /\.pkg$/i,
exe: /\.exe$/i,
msi: /\.msi$/i,
zip: /\.zip$/i,
tar: /\.(tar(\.?(gz)?)|tgz)/i,
'7z': /\.7;$/i
tar: /\.tar\..*$/i,
'7z': /\.7z$/i
};
/**
@@ -66,12 +77,18 @@ function getAllReleases(request, owner = 'BurntSushi', repo = 'ripgrep') {
const name = asset['name'];
const os =
Object.keys(osMap).find((regKey) => {
name.match(osMap[regKey]);
}) || 'linux';
const arch = Object.keys(archMap).find((regKey) =>
name.match(archMap[regKey])
);
Object.keys(osMap).find(function (regKey) {
//console.log('github release os:', name, regKey, osMap[regKey]);
return osMap[regKey].test(name);
}) || 'unknown';
var arch;
archArr.some(function (regKey) {
//console.log('github release arch:', name, regKey, archMap[regKey]);
arch = name.match(archMap[regKey]) && regKey;
if (arch) {
return true;
}
})[0];
let fileExt = '';
Object.keys(fileExtMap).find((regKey) => {
@@ -85,10 +102,11 @@ function getAllReleases(request, owner = 'BurntSushi', repo = 'ripgrep') {
all.releases.push({
download: asset['browser_download_url'],
date: release['published_at'],
version: release['tag_name'],
lts: !release['prerelease'],
ext: fileExt,
date: (release['published_at'] || '').replace(/T.*/, ''),
version: release['tag_name'], // TODO tags aren't always semver / sensical
lts: /\b(lts)\b/.test(release['tag_name']),
channel: !release['prerelease'] ? 'stable' : 'beta',
ext: fileExt.slice(1),
arch,
os
});

18
rg/releases.js Normal file
View File

@@ -0,0 +1,18 @@
'use strict';
var github = require('../_common/github.js');
var owner = 'BurntSushi';
var repo = 'ripgrep';
module.exports = function (request) {
return github(request, owner, repo).then(function (all) {
return all;
});
};
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
console.log(JSON.stringify(all));
//console.log(JSON.stringify(all, null, 2));
});
}

89
rg/rg.bash Normal file
View File

@@ -0,0 +1,89 @@
# title: Ripgrep
# homepage: https://github.com/BurntSushi/ripgrep
# tagline: a modern drop-in grep replacement
# alias: rg
# description: |
# '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.
# examples: |
#
# ```bash
# rg <search-term> # searches recursively, ignoing .git, node_modules, etc
# ```
#
# ```bash
# rg 'function doStuff'
# ```
#
# ```bash
# rg 'doStuff\(.*\)'
# ```
set -e
set -u
set -o pipefail
# Use the script's first argument or the supplied WEBI_VERSION or ''
WEBI_VERSION=${1:-${WEBI_VERSION:-}}
# Set a temporary directory, if not already set
WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-ripgrep.XXXXXXXX)"}
###################
# Get WEBI vars #
###################
# The WEBI bootstrap will define these
# but each script should be testable in its own right
if [ -z "${WEBI_PKG_URL}" ]; then
release_tab="${WEBI_HOST}/api/releases/ripgrep@${WEBI_VERSION:-}.csv?os=$(uname -s)&arch=$(uname -m)&ext=tar&limit=1"
WEBI_CSV=$(curl -fsSL "$release_tab" -H "User-Agent: $(uname -a)")
WEBI_CHANNEL=$(echo $WEBI_TAB | cut -d ',' -f 3)
if [ "error" == "$WEBI_CHANNEL" ]; then
echo "could not find release for ripgrep v${WEBI_VERSION}"
exit 1
fi
WEBI_VERSION=$(echo $WEBI_TAB | cut -d ',' -f 1)
WEBI_PKG_URL=$(echo $WEBI_TAB | cut -d ',' -f 9)
WEBI_PKG_FILE="$WEBI_TMP/$(echo $WEBI_PKG_URL | sed s:.*/::)"
fi
###################
# Install ripgrep #
###################
new_rg="${HOME}/.local/bin/rg"
# Test for existing version
set +e
cur_rg="$(command -v rg)"
set -e
if [ -n "$cur_rg" ]; then
cur_ver=$(rg --version | head -n 1 | cut -d ' ' -f 2)
if [ "$cur_ver" == "$WEBI_VERSION" ]; then
echo "ripgrep v$WEBI_VERSION already installed at $cur_rg"
exit 0
elif [ "$cur_rg" != "$new_rg" ]; then
echo "WARN: possible conflict with ripgrep v$WEBI_VERSION at $cur_rg"
fi
fi
# TODO move download to the webi bootstrap
echo Downloading ripgrep v"${WEBI_VERSION}" from "${WEBI_PKG_URL}"
curl -fsSL "${WEBI_PKG_URL}" -o "${WEBI_PKG_FILE}"
pushd "${WEBI_TMP}" 2>&1 >/dev/null
echo Installing ripgrep v${WEBI_VERSION} as "$new_rg"
tar xf "${WEBI_PKG_FILE}"
rm "${WEBI_PKG_FILE}"
mv ./ripgrep-*/rg "${HOME}/.local/bin/"
popd 2>&1 >/dev/null
###################
# Update PATH #
###################
# TODO get better output from pathman / output the path to add as return to webi bootstrap
pathman add "$HOME/.local/bin/"
echo "Installed 'rg'"
echo ""

18
ripgrep/releases.js Normal file
View File

@@ -0,0 +1,18 @@
'use strict';
var github = require('../_common/github.js');
var owner = 'BurntSushi';
var repo = 'ripgrep';
module.exports = function (request) {
return github(request, owner, repo).then(function (all) {
return all;
});
};
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
console.log(JSON.stringify(all));
//console.log(JSON.stringify(all, null, 2));
});
}

9
ripgrep/ripgrep.bash Normal file
View File

@@ -0,0 +1,9 @@
# title: Ripgrep (alias)
# homepage: https://webinstall.dev/rg
# tagline: `ripgrep` (project) is an alias for `rg` (command)
# alias: rg
# description: |
# See https://webinstall.dev/rg
echo "'ripgrep' (project) is an alias for 'rg' (command)"
curl -fsSL https://webinstall.dev/rg@${WEBI_VERSION:-} | bash