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:
parent
1ae160109c
commit
da8ccb7564
1 changed files with 55 additions and 0 deletions
55
main/common.sh
Normal file
55
main/common.sh
Normal 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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in a new issue