Bash filters validators

Pierre Fromager ab7bc48455 doc : README 11 月之前
src 3a7709038f clean : remove export 11 月之前
test 34e28962c0 doc : README 11 月之前
README.md ab7bc48455 doc : README 11 月之前

README.md

Bafiva

bash filters and validators collection.

All validators return either 0 or 1

Usage

From shell

Provide the validators file path preceded by dot then call validator

$ . /apath/to/src/validators.sh && echo $(isurl 'https://host.domain.tld')
1
$ . rpath/to/validators.sh && [[ $(isurl 'https://host.domain.tld') -eq 1 ]] && echo 'Happy' || echo 'Sad'
Happy
$ . rpath/to/validators.sh && [[ $(isurl 'phone://host.domain.tld') -eq 0 ]] && echo 'No' || echo 'Yes'
No
$ . rpath/to/validators.sh && (($(iscomment '  # commented'))) && echo ';)' || echo '^^'
;)

From script

Just source the filter or validator file with a correct path as below.

#!/bin/bash

source /a/path/to/bafiva/src/validators.sh
source /a/path/to/bafiva/src/filters.sh

Persitence

From an existing shell session sourcing once let validators to be ready until end session.

Sourcing validators.sh or filters.sh in your .bashrc bypass the first source requirement.

Thus command will be available from your autocompletion shell on prompt tabulating.

$ is<tab>
ischroot                  iscidr6                   isdv4-serial-debugger     isip4                     ispell                    isurl                     
iscidr4                   iscomment                 isdv4-serial-inputattach  isip6                     ispell-wrapper   
$ isip4 192.168.168.168
1

Detail

Filters

  • int2ip
  • ip2int
  • ipdesag
  • tocoma

Validators

  • isurl
  • iscomment
  • isip4
  • isip6
  • iscidr4
  • iscidr6

Dependencies

Filter ipdesag requires ipcalc binary to be installed.

Tests

Validators suites will be rendered.

$ . /a/path/to/bafiva/test/validators.sh

Contribute

Make pull request and don't forget to make the corresponding test before.