filter

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

🌳Go Filter Library

WIP GoDoc License Go Report Card Coverage

Usage

z filter yt link
filter yt link
z yt link

📺 https://youtu.be/8st1NhaKDCA

Example Bash Filters to Convert

This one adds Go badges:

#!/usr/bin/env bash

url="$1"

if [[ -e go.mod ]];then
  url=$(head -1 go.mod)
  url=${url#* }
fi

echo "![WIP](https://img.shields.io/badge/status-wip-red.svg)"
echo "[![GoDoc](https://godoc.org/$url?status.svg)](https://godoc.org/$url)"
echo "[![License](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](LICENSE)"
echo "[![Go Report Card](https://goreportcard.com/badge/$url)](https://goreportcard.com/report/$url)"
echo "[![Coverage](https://gocover.io/_badge/$url)](https://gocover.io/$url)"
echo

Universal way to comments:

#!/usr/bin/env bash

while IFS= read -r line; do
  echo "${1:-#} $line"
done

Detect and replace emojis on save:

#!/usr/bin/env bash

declare -A emoji
emoji[smile]=😃
emoji[bear]=🐻
emoji[hamburger]=🍔
emoji[lightbulb]=💡
emoji[idea]=💡
emoji[comment]=💬
emoji[chat]=💬
emoji[pomo]=🍅
emoji[stop]=🛑
emoji[warning]=⚠️
emoji[rant]=🤬
emoji[tv]=📺
emoji[update]=📰
emoji[tux]=🐧
emoji[tux]=🐧
emoji[facepalm]=🤦

toemoji() {
  local in=/dev/stdin
  local out=/dev/stdout
  local file="$1"
  if [[ -n $file ]];then
    in="$file"
    out="$(mktemp)"
  fi
  IFS=$'\n'
  while read -r line; do
    for k in ${!emoji[@]}; do
      line=${line//:$k:/${emoji[$k]}}
    done
    echo "$line" >> $out
  done < "$in"
  if [[ -n $file ]]; then
    cp "$out" "$file"
    rm "$out"
  fi
}

toemoji "$@"

Here's how you would change VIM:

autocmd BufWritePost *.md silent !toemoji %

Total all lines beginning with numbers:

#!/usr/bin/env bash

while read line; do
  n=${line%%|*}
  [[ ${line##*|} == TOTAL ]] && continue
  ((total+=n))
  echo $line
done
echo $total\|TOTAL

Documentation

Overview

Package filter contains several subpackage collections of filter functions for use from Bonzai stateful command trees or just by themselves.

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &Z.Cmd{
	Name:      `filter`,
	Aliases:   []string{`filt`},
	Summary:   `collection of common UNIX filters`,
	Commands:  []*Z.Cmd{help.Cmd, youtube.Cmd},
	Copyright: `Copyright 2022 Robert S Muhlestein`,
	Version:   `v0.1.0`,
	License:   `Apache-2.0`,
	Site:      `rwxrob.tv`,
	Source:    `git@github.com:rwxrob/filter.git`,
	Issues:    `github.com/rwxrob/filter/issues`,
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
filter command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL