8000 GitHub - pschmitt/colors.jq: jq module to colorize output manually
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

pschmitt/colors.jq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

🎨 colors.jq

This jq module provides some low-level functions for colorizing the output.

It is intended to be used in conjunction with jq's raw output mode, which does not do any coloring on its own.

🔨 Installation

Grab ./colors.jq and put it in jq's include path.

🍧 Usage

The following snippet assumes that you cloned this repository in the current directory:

echo '{"test": "✅ this should be green, bold and blinking"}' | \
  jq -L "$PWD/colors.jq" -r '
    import "colors" as c;
    c::blink(c::bold(c::green(.test)))'

💫 Bonus: ZSH wrapper function

For your convenience here's a little shell (zsh only!) function that alleviates the pain of importing the module at every run:

jqcolor () {
	local help
	zparseopts -D -E h=help -help=help

	if [[ -n "$help" ]]
	then
		jq --help
		return
	fi

	local filter="import \"colors\" as c; ${@[-1]}"

  # Remove last arg (ie the original filter)
	set -- ${@[1,-2]}
	jq -L "${XDG_CONFIG_HOME}/jq" $@ $filter
}

Once loaded you can:

echo '{"test": "make this red"}' | \
  jqcolor -r "c::red(.test)"

About

jq module to colorize output manually

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Languages

0