feat: Initial commit.

This commit is contained in:
Spencer Brower
2024-01-08 13:35:14 -05:00
commit 555073c428
7 changed files with 114 additions and 0 deletions

22
filters.nu Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env -S nu --stdin
def "parse filter" [
] {
$in | parse --regex '^(?<name>[^=]+)=(?<params>.*)' | first |
update params {|row| $row.params | parse --regex `(?<param>[^=]+)=(?<value>[^:]+):?` }
}
def "filter to-string" [] {
each { |filter| $'($filter.name)=($filter.params | format '{param}={value}')' } |
str join ':'
}
def "complex-filters to-string" [
--pretty-print (-p)
]: table<input: list<string>, filters: table<name: string, params: table<param: string, value: string>>, output: string> -> string {
$in | update filters {
|$row| $row.filters | flatten | filter to-string
} | update input { |row|
$row.input | str join ']['
} | format '[{input}]{filters}[{output}]' | str join (";" + (if $pretty_print { "\n" } else { "" })) | str replace --all '[]' ''
}