Skip to content

Instantly share code, notes, and snippets.

View piotr-semenov's full-sized avatar

Piotr Semenov piotr-semenov

  • Yerevan, Armenia
  • 00:48 (UTC +04:00)
View GitHub Profile
@piotr-semenov
piotr-semenov / brew_search.sh
Created November 14, 2023 21:47
RegEx search in Homebrew formulas/casks
#!/bin/bash
function brew_search {
echo -e "FullName\tShortName\tHomepage\tDescription" &&\
curl -s -k -X GET https://formulae.brew.sh/api/{formula,cask}.json |\
jq ". + input" |\
jq -r ".[] | select(.desc | . != null and (ascii_downcase | match(\"$1\"))) | [.full_token // .full_name, .token // .name, .homepage, .desc] | @tsv"
}
@piotr-semenov
piotr-semenov / variadic_option.py
Last active January 3, 2023 14:21
Support variadic options for python's popular click CLI (https://github.com/pallets/click/)
from itertools import takewhile
from typing import Any, Callable, Set
import click
class VariadicOption(click.Option):
"""Variadic option for python-click CLI.
"""
_processor: Callable[..., Any]
@piotr-semenov
piotr-semenov / toopts.sh
Last active January 20, 2023 19:35
How to process JSON as command line options in BASH?
#!/bin/bash
function toopts {
jq -r 'to_entries | map("--\(.key)\n\(.value | if type=="array" then map(@text) | join("\n") else . end)")[]' "$1";
}