basic.sh new functions
This commit is contained in:
@@ -5,6 +5,34 @@ source $( dirname $(readlink -e -- "${BASH_SOURCE}"))/io.sh || exit 255
|
|||||||
# Little handy helpers for scripting
|
# 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
|
# convert relative path $1 to full one
|
||||||
abspath() {
|
abspath() {
|
||||||
echo $(realpath -q "${1/#\~/$HOME}")
|
echo $(realpath -q "${1/#\~/$HOME}")
|
||||||
@@ -93,3 +121,7 @@ is_int() {
|
|||||||
is_number() {
|
is_number() {
|
||||||
[[ "$1" =~ ^[0-9]+([.,][0-9]+)?$ ]]
|
[[ "$1" =~ ^[0-9]+([.,][0-9]+)?$ ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trim() {
|
||||||
|
echo "$1" | xargs
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user