Skip to content

jq module to colorize output manually

License

Notifications You must be signed in to change notification settings

pschmitt/colors.jq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 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)"

Releases

No releases published

Packages

No packages published

Languages