Implement opoo in bash
This commit is contained in:
parent
efd29ebaca
commit
2498d99a14
@ -1,20 +1,35 @@
|
|||||||
HOMEBREW_VERSION="0.9.9"
|
HOMEBREW_VERSION="0.9.9"
|
||||||
|
|
||||||
onoe() {
|
o() {
|
||||||
if [[ -t 2 ]] # check whether stderr is a tty.
|
|
||||||
then
|
|
||||||
echo -ne "\033[4;31mError\033[0m: " >&2 # highlight Error with underline and red color
|
|
||||||
else
|
|
||||||
echo -n "Error: " >&2
|
|
||||||
fi
|
|
||||||
if [[ $# -eq 0 ]]
|
if [[ $# -eq 0 ]]
|
||||||
then
|
then
|
||||||
/bin/cat >&2
|
/bin/cat
|
||||||
else
|
else
|
||||||
echo "$*" >&2
|
echo "$*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highlight() {
|
||||||
|
if [[ -t 1 ]] # check whether stdout is a tty.
|
||||||
|
then
|
||||||
|
echo -ne "\033[4;$1m$2\033[0m"
|
||||||
|
else
|
||||||
|
echo -n "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
opoo() {
|
||||||
|
highlight 33 Warning >&2 # yellow
|
||||||
|
echo -n ": " >&2
|
||||||
|
o "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
onoe() {
|
||||||
|
highlight 31 Error >&2 # red
|
||||||
|
echo -n ": " >&2
|
||||||
|
o "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
odie() {
|
odie() {
|
||||||
onoe "$@"
|
onoe "$@"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user