bsf/bsf.sh

46 lines
1.2 KiB
Bash

#!/bin/bash
##### bash framework
# some useful bash functions to make things easier
## use printf for safety purposes
# http://www.etalabs.net/sh_tricks.html
# @param string what to say
say () { printf %s\\n "$*" ; }
sayn () { printf %s "$*" ; }
## check if user is root
root () { [[ "$EUID" -eq 0 ]] ; }
## check if last call had errors
## if yes print generic error message and exit
ok() { [[ "$?" -ne 0 ]] && echo "ERROR, aborting." && exit 1; }
## colors
# use ANSI escape codes
normal () { printf '\033[0m' ; }
red () { printf '\033[0;31m' ; }
green () { printf '\033[0;32m' ; }
black () { printf '\033[0;30m' ; }
brown () { printf '\033[0;33m' ; }
orange () { printf '\033[0;33m' ; }
blue () { printf '\033[0;34m' ; }
purple () { printf '\033[0;35m' ; }
cyan () { printf '\033[0;36m' ; }
gray () { printf '\033[0;37m' ; }
grey () { printf '\033[1;30m' ; }
lred () { printf '\033[1;31m' ; }
lgreen () { printf '\033[1;32m' ; }
yellow () { printf '\033[1;33m' ; }
lblue () { printf '\033[1;34m' ; }
lpurple (){ printf '\033[1;35m' ; }
lcyan () { printf '\033[1;36m' ; }
white () { printf '\033[1;37m' ; }
# quick styler, usage "style *color*"
style() {
[[ "$1" == "" ]] && orange || $1
sayn " ::: "
normal
}