Blush - highlight matches with any colours of your choice

Overview

Blush

PkgGoDev GitHub go.mod Go version Build Status License: MIT Coverage Status Go Report Card

With Blush, you can highlight matches with any colours of your choice.

1

  1. Install
  2. Usage
  3. Arguments
  4. Colour Groups
  5. Colours
  6. Complex Grep
  7. Suggestions
  8. License

Install

You can grab a binary from releases page. If you prefer to install it manually you can get the code and install it with the following command:

$ go install github.com/arsham/[email protected]

Make sure you have go>=1.18 installed.

Usage

Blush can read from a file or a pipe:

$ cat FILENAME | blush -b "print in blue" -g "in green" -g "another green"
$ cat FILENAME | blush "some text"
$ blush -b "print in blue" -g "in green" -g "another green" FILENAME
$ blush "some text" FILENAME

Note

Although this program has a good performance, but performance is not the main concern. There are other tools you should use if you are searching in large files. Two examples:

Normal Mode

This method shows matches with the given input:

$ blush -b "first search" -g "second one" -g "and another one" files/paths

Any occurrence of first search will be in blue, second one and and another one are in green.

2

Dropping Unmatched

By default, unmatched lines are not dropped. But you can use the -d flag to drop them:

3

Arguments

Argument Shortcut Notes
N/A -i Case insensitive matching.
N/A -R Recursive matching.
--no-filename -h Suppress the prefixing of file names on output.
--drop -d Drop unmatched lines

File names or paths are matched from the end. Any argument that doesn't match any files or paths are considered as regular expression. If regular expressions are not followed by colouring arguments are coloured based on previously provided colour:

$ blush -b match1 match2 FILENAME

4

Notes

  • If no colour is provided, blush will choose blue.
  • If you only provide file/path, it will print them out without colouring.
  • If the matcher contains only alphabets and numbers, a non-regular expression is applied to search.

Colour Groups

You can provide a number for a colour argument to create a colour group:

$ blush -r1 match1 -r2 match2 -r1 match3 FILENAME

5

All matches will be shown as blue. But match1 and match3 will have a different background colour than match2. This means the numbers will create colour groups.

You also can provide a colour with a series of match requests:

$ blush -r match1 match3 -g match2 FILENAME

Colours

You can choose a pre-defined colour, or pass it your own colour with a hash:

Argument Shortcut
--red -r
--green -g
--blue -b
--white -w
--black -bl
--yellow -yl
--magenta -mg
--cyan -cy

You can also pass an RGB colour. It can be in short form (--#1b2, -#1b2), or long format (--#11bb22, -#11bb22).

6

Complex Grep

You must put your complex grep into quotations:

$ blush -b "^age: [0-9]+" FILENAME

7

Suggestions

This tool is made to make your experience in terminal a more pleasant. Please feel free to make any suggestions or request features by creating an issue.

License

Use of this source code is governed by the MIT License. License file can be found in the LICENSE file.

Comments
  • doesn't compile on Debian9 with go1.7.4 / go minimum version

    doesn't compile on Debian9 with go1.7.4 / go minimum version

    I have Debian 9 Stretch and go get doesn't work

    $ go version
    go version go1.7.4 linux/amd64
    
    $ go get github.com/arsham/blush
    # github.com/arsham/blush/cmd
    opt/go/src/github.com/arsham/blush/cmd/args.go:78: undefined: sort.SliceStable
    opt/go/src/github.com/arsham/blush/cmd/args.go:118: undefined: sort.SliceStable
    opt/go/src/github.com/arsham/blush/cmd/args.go:122: undefined: sort.SliceStable
    

    SliceStable seems to be introduced with 1.8, https://golang.org/doc/go1.8 ? So maybe the readme needs an update?

    opened by kiuuik 5
  • test: use `T.TempDir` to create temporary test directory

    test: use `T.TempDir` to create temporary test directory

    A testing cleanup.

    This pull request replaces ioutil.TempDir with t.TempDir. We can use the T.TempDir function from the testing package to create temporary directory. The directory created by T.TempDir is automatically removed when the test and all its subtests complete.

    Reference: https://pkg.go.dev/testing#T.TempDir

    func TestFoo(t *testing.T) {
    	// before
    	tmpDir, err := ioutil.TempDir("", "")
    	require.NoError(t, err)
    	defer require.NoError(os.RemoveAll(tmpDir))
    
    	// now
    	tmpDir := t.TempDir()
    }
    
    opened by Juneezee 2
  • Could you explain how to install/run?

    Could you explain how to install/run?

    Could you explain how to install/run? I've already installed golang... what then, I'm on ubuntu, but i suppose it's quite similar for everyones go installation.

    enhancement 
    opened by pulketo 2
  • Set the default mode not to drop lines

    Set the default mode not to drop lines

    In this PR the default mode is just colouring matches.

    This is a major change but I am not planning to bump the version.

    BREAKING CHANGE: from this commit we only support go version 1.18 and newer.

    Please explain the changes you made here.

    Checklist

    • [X] Code compiles correctly
    • [X] Created tests which fail without the change (if possible)
    • [X] All tests passing
    • [X] Ran tests with -race flag
    • [X] Extended the README / documentation, if necessary
    opened by arsham 1
  • Help flag

    Help flag

    No help flag available from the CLI. Can't expect people to continually reference the github docs. Any reason not to do this? If not I'll look at it and put in a PR this weekend.

    enhancement 
    opened by bpsizemore 1
  • Not really an issue...

    Not really an issue...

    Just a suggestion but you might want to switch to a simpler prompt for your screenshots. The one you're using is cool and everything but a little distracting when we really just want to see how the results are getting colored.

    good first issue 
    opened by okonomiyaki3000 1
  • Rewrite WriteTo and Read functions of Blush

    Rewrite WriteTo and Read functions of Blush

    At the moment, WriteTo() function uses bufio.Scanner() with a custom buffer and a large token size in order to read from readers line by line, which is not ideal. On the other hand, Read() uses a bytes.Buffer instance and reads everything on first call. Both of these methods require refactoring.

    WriteTo (1)

    This method should request the next available line or more if required (2), and call Find() methods of all finders, keeping the results in a buffer. Then it should write up to length of given io.Writer, while keeping the rest of the buffer for the next try, until it processes everything.

    Read

    This method shares most of WriteTo()'s logic.

    Notes

    • (1) io.Copy() uses WriteTo if available, then Read() method.
    • (2) Next available line(s) should be enough to fill the provided Writer or byte slice.
    • There is a single reader in Blush struct, which is either os.Stdin or reader.MultiReader and when its Read() method is called, it automatically closes previously processed reader and opens the next one. Therefore there is no action required here.
    • Reads can be split in the middle of colouring. This means the terminal's codes for colouring could span between read calls. Therefore it should unformat if there's been an interruption in between, otherwise it could mess up the terminal's colours.
    • In case of reader.MultiReader usage, if any filed isn't ended with a new line and readers rotate, it should account for a new line in between operations.
    help wanted 
    opened by arsham 0
Releases(v0.6.0)
Owner
Arsham Shirvani
Senior Software Engineer at Blokur. I'm a Gopher and I love GNU/Linux and Neovim.
Arsham Shirvani
Sense your go module as iTerm2 tab colours

Synesthesia updates your iTerm2 tab colours depending on the go module name in your directory ancestry.

Rory Quinn 8 Aug 10, 2022
Watch your favourite anime using the video player of your choice directly from the command line

anime-cli Watch your favourite anime using the video player of your choice direc

Ruben Dewitte 4 Feb 10, 2022
A client for managing authzed or any API-compatible system from your command line.

zed A client for managing authzed or any API-compatible system from your command line. Installation zed is currently packaged by as a head-only Homebr

authzed 44 Aug 28, 2022
A CLI tool to find the absolute path of any folder in your local file system.

Table of Contents What is this? How to use this Examples of usage How to compile it What am I looking at It's a CLI tool that I made for finding the a

Benyakir Horowitz 0 Jan 15, 2022
Are you programming and suddenly your stomach is rumbling? No problem, order your Ifood without leaving your favorite text editor ❤️

vim-ifood Você ta programando e de repente bateu aquela fome? Sem problemas, peça seu Ifood sem sair do seu editor de texto favorito ❤️ Are you progra

Felipe Volpone 4 Jun 2, 2022
Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.

Sensible and fast command-line flag parsing with excellent support for subcommands and positional values. Flags can be at any position. Flaggy has no

Eric Greer 812 Sep 26, 2022
Make any Go function into a API (FaaS)

faas Make any (Go) function into an API with one HTTP request. This is a FaaS: functions as a service. But, in actuality, its more of a FaaSSS: functi

Zack 91 Jun 4, 2022
🔹 Golang module to move the terminal cursor in any direction on every operating system.

AtomicGo | cursor Get The Module | Documentation | Contributing | Code of Conduct Description Package cursor contains cross-platform methods to move t

AtomicGo 47 Sep 16, 2022
a work time management CLI tool for any platform

english |日本語 jobgosh | job management tool made with golang for shell a multi-platform work time management CLI tool to track and improve your day to

奥田 龍馬 10 May 16, 2022
🚀 Get Youtube Live stream chat feed without any authentication!

youtube-live-chat-downloader Fetches Youtube live chat messages with no authentication required. How does it work? The request for fetching live chat

Abhinav Raut 9 Sep 12, 2022
Cli tool to translate text from any language into german

GERMAN A cli tool for converting text into German. Build Locally $> go build $> go install Dependencies To execute successfully, a free tier DEEPL API

Kieran O'Sullivan 3 Jan 24, 2022
🏗️ Fetch a specific commit without any history (shallow depth w/o cloning)

shallow-fetch-sha ??️ For a given git repository and commit, fetch and checkout just that commit without any history. This can be extremely useful in

Rob Herley 0 Nov 27, 2021
Portal is a quick and easy command-line file transfer utility from any computer to another 🖥️ 🌌 💻

Portal is a quick and easy command-line file transfer utility from any computer to another ??️ ?? ??

Zino Kader 215 Sep 20, 2022
ntest is a cross-platform cli app that runs multiple tests against any address.

ntest ntest is a cross-platform cli app that runs multiple tests against any address. About ntest Having the ability to run common tests against any d

Bruno Schaatsbergen 13 Jan 3, 2022
A client-side agent that connects any Kubernetes cluster to AWS

EKS Connector EKS Connector is a client-side agent that connects any Kubernetes cluster to AWS. How it works EKS Connector runs in Kubernetes as a Pod

Amazon Web Services 27 Sep 2, 2022
Generate an interactive, autocompleting shell for any Cobra CLI

cobra-shell Description Leverages the Cobra completion API to generate an interactive shell for any Cobra CLI, powered by go-prompt. On-the-fly autoco

Brian Strauch 29 Aug 31, 2022
An excellent tool for converting json files to structs or classes in any programming language.

Explore Usage » Report Bug · Request Feature Table of Contents About The Project Supported Languages Getting Started Usage Parameters Set Up Your Own

ez4o 12 Jan 28, 2022
A terminal designed for anyone to use and designed for any platform

A terminal designed for anyone to use and designed for any platform. Which includes the basic features of any terminal and includes friendly commands to perform tools such as ping, traceroute, generate key pairs, encrypt/decrypt, router security actions, etc. All of the source code is done in Go.

Karun Kanda 1 Jan 25, 2022
The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine

The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine. This is a work in progress project for TCSS 401X :)

cam 6 May 29, 2022