npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bash-rex

v0.7.2

Published

A simple regexp executer for bash

Downloads

5

Readme

rex

A simple regexp executer for bash.

Like sed, but you don't need to deal with complex escape characters.

It uses node regexp. Could not be simpler to use!

Installation

You can install using npm:

npm i -g bash-rex

Or yarn:

yarn global add bash-rex

Or download the bin from github (it comes with node bundled in, so it runs on any x64 linux box):

wget https://github.com/luanpotter/rex/raw/master/dist/rex
chmod +x rex
sudo mv rex /usr/bin/rex

The bin bundle is a bit heavy because of the node inclusion, so if you have node, prefer the former methods as they are really, really lightweight (1.3K).

Usage

Very simple! Just run:

echo 'foo' | rex 'o' 'e'
> fee

But unlike sed, you don't need to escape complex regex'es:

echo 'package-name-1.2.3' | rex '(\w)-\d[\d-.:+]*' '$1'
> package-name

Just use single quotes so bash won't replace stuff like $1.

If you want to change a file, you can use sponge:

echo 'foo' > file
cat file | rex 'foo' 'bar' | sponge file
cat file

Install sponge for Arch Linux:

sudo pacman -S moreutils

No escape!

Almost nothing needs to be escaped.

The first parameter is a pure node regex, that will be run with the flags 'mg' (multiline and global). More information here.

The second parameter will be the replacement literally, except for:

  • $n, where n is a number, will become the n-th capture group (starting on $1).
  • \t will become tab, \n will become newline, \r will become carriage return, \$ will become $ and \\ will become \

More options

It's supposed to be simple: if you want simple, stop reading. If you want a few more options, there are flags:

  • -h : if present, won't run, just show the help section
  • -f : if present, the stdin becomes a new-line separated list of files, and rex will perform the replace on those files
  • -b : if present, the backup mode is active:
    • if not on -f, rex will output stdin as is, but will save the changes to a __rex__.bak file with the requested changes
    • if on -f, it will replace on every file specified, but the originals will be saved on *.bak files alongside the altered files

Beware when using the -f flag: rex will open every file as UTF-8. If you pipe binary files to rex, it will mess them up. Always use something like find, grep or ag to pipe only relevant files.

There are more examples here.