add: common.sh and modified

from: https://cuynutt.ddns.net/mbcp/mbbpatch/src/branch/dev/MBCPApp/common.sh
author: fukiame, cuynu

Signed-off-by: ncatt <ncatt@noreply.cuynutt>
This commit is contained in:
Nguyen Cao An Tuong 2026-04-22 20:32:39 +07:00
commit c209ec7376

55
common.sh Normal file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env bash
# vim: expandtab tabstop=4 shiftwidth=4
# imported from https://github.com/dylanaraps/pure-bash-bible
bb_split() {
# Usage: split "string" "delimiter" "count"
IFS=$'\n' read -d "" -ra arr <<< "${1//$2/$'\n'}"
# printf '%s\n' "${arr[@]}"
printf '%s\n' "${arr[$3]}"
}
# imported from https://github.com/dylanaraps/pure-sh-bible
lstrip() {
# Usage: lstrip "string" "pattern"
printf '%s\n' "${1##$2}"
}
# imported from https://github.com/dylanaraps/pure-sh-bible
rstrip() {
# Usage: rstrip "string" "pattern"
printf '%s\n' "${1%%$2}"
}
# imported from https://github.com/dylanaraps/pure-bash-bible
strip_all() {
# Usage: strip_all "string" "pattern"
printf '%s\n' "${1//$2}"
}
good() {
echo -e "\033[32m[$(date +"%H:%M:%S:%2N")] [INFO] $1\033[0m"
}
info() {
echo "[$(date +"%H:%M:%S:%2N")] [INFO] $1"
}
warn() {
echo -e "\033[33m[$(date +"%H:%M:%S:%2N")] [WARN] $1\033[0m"
}
err() {
echo -e "\033[31m[$(date +"%H:%M:%S:%2N")] [ERROR] $1\033[0m"
}
confirm() {
read -rp "$1
Press Y to confirm, press any other keys to cancel: " val
case "$val" in
Y|y|yes|Yes) : ;;
*) return 69 ;;
esac
}