| ... | ... |
@@ -38,6 +38,7 @@ distro-url [query] [guess] [<distro> [<variant> [<arch> [<codename> [<version> [ |
| 38 | 38 |
- [POSIX][] [shell][]. |
| 39 | 39 |
- `column`, optional, for formatting. |
| 40 | 40 |
- `curl`, optional, for query mode. |
| 41 |
+- `tput`, optional, for color. |
|
| 41 | 42 |
|
| 42 | 43 |
[POSIX]: https://en.wikipedia.org/wiki/POSIX |
| 43 | 44 |
[shell]: https://en.wikipedia.org/wiki/Unix_shell |
| ... | ... |
@@ -27,11 +27,23 @@ main() |
| 27 | 27 |
done |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 |
+colorize() |
|
| 31 |
+{
|
|
| 32 |
+ if [ "$(command -v tput)" ] && [ -t 1 ] |
|
| 33 |
+ then |
|
| 34 |
+ tput setaf "$1" |
|
| 35 |
+ printf '%s' "$2" |
|
| 36 |
+ tput sgr0 |
|
| 37 |
+ else |
|
| 38 |
+ printf '%s' "$2" |
|
| 39 |
+ fi |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 30 | 42 |
query() |
| 31 | 43 |
{
|
| 32 | 44 |
curl -sfI "$1" > '/dev/null' \ |
| 33 |
- && printf '%s' 'OK' \ |
|
| 34 |
- || printf '%s' 'ERR' |
|
| 45 |
+ && colorize 10 'OK' \ |
|
| 46 |
+ || colorize 9 'ERR' |
|
| 35 | 47 |
} |
| 36 | 48 |
|
| 37 | 49 |
filter() |