diff --git a/helpers/basic.sh b/helpers/basic.sh index e3e9ed4..e301d32 100644 --- a/helpers/basic.sh +++ b/helpers/basic.sh @@ -5,6 +5,34 @@ source $( dirname $(readlink -e -- "${BASH_SOURCE}"))/io.sh || exit 255 # Little handy helpers for scripting ######################################################## +is_bash() { + [[ "$(basename "$SHELL")" != "bash" ]] +} + +is_sourced() { + [[ "${BASH_SOURCE[0]}" != "$0" ]] +} + +is_root() { + [[ "$(id -u)" -ne 0 || $(ps -o comm= -p $PPID) == "sudo" ]] +} + +get_os() { + case "$(uname -s)" in + Linux*) echo Linux ;; + Darwin*) echo Macos ;; + CYGWIN*) echo Cygwin ;; + MINGW*) echo MinGw ;; + MSYS_NT*) echo Git ;; + *) return 1 ;; + esac +} + +get_os_id() { + [ -f /etc/os-release ] && source /etc/os-release + echo "$ID" +} + # convert relative path $1 to full one abspath() { echo $(realpath -q "${1/#\~/$HOME}") @@ -93,3 +121,7 @@ is_int() { is_number() { [[ "$1" =~ ^[0-9]+([.,][0-9]+)?$ ]] } + +trim() { + echo "$1" | xargs +}