It is the toolset for the developing bash scripts.
#!/bin/bash
if [ ! -d $HOME/.bashkit/ ]; then echo 'Install `~/.bashkit/`'; git clone git@github.com:RubaXa/bashkit.git $HOME/.bashkit; fi
source "$HOME/.bashkit/all.sh";
inputRead "Enter %username%:" name;
hrLine $(logDone "Hi, $name" $(emojiStatus "ok"));
inputReadYesNo "Are you wish to play even/odd?" game $Y;
if [[ $game == $Y ]]; then
echo "";
while : ; do
inputReadChar "Even/Odd (e/o)?:" ans
num=$RANDOM;
echo -n "Number $num is" ""
if (( $num % 2 == 0 )); then echo -n "Even!"; res="e";
else echo -n "Odd!"; res="o"; fi
if [[ $res == $ans ]]; then
echo "" $(colorize $COLOR_DONE "You WIN!") $(emojiStatus done);
else
echo "" $(colorize $COLOR_ERR "You LOOSE!") $(emojiStatus err);
fi
echo ""
done
fi
- AutoUpdate support 🚀
- Easy and intuitive development 💡
- Logging (levels supports), Colors and Emoji 😁
- Documentation 📑
- Verbose mode ✴️ (just add
--verbose
)
./all.sh --bashkit-docs
— Docs generator.
riskCreate [branch] [deploy]
- [branch] — create risk for git-branch
- [deploy] — push & switch created tarball to risk branch
riskPush name branch
- name — tarball name
- branch — risk branch
riskSwitch name branch
- name — tarball name
- branch — risk branch
riskAlpha name
- name — tarball name
riskRemove name [branch=trb]
- name — tarball name
- [branch=trb] — risk branch
riskAutoRemove [branch]
- [branch] — risk branch
riskGetList [branch]
- [branch] — risk branch
fsGetFiles path [depth=1]
fsReadFile file
fsWriteFile file content
fsReplaceInFile file pattern value
fsReplaceInFiles path pattern value
fsFileExists file
fsReadFileIfExists file
inputRead text ref
inputReadSecure text ref
inputReadChar text ref
inputReadYesNo text ref [def=$N] [attempts=2]
inputSelect text ref ...items
- ref — will contains a selected index
arrayIncludes value ...list
- ...list — for example
arrayIncludes "y" "x" "y"
, orarrayIncludes $val ${list[@]}
stringTest regex value
stringGetMatch regex value
stringGetMatches regex value
stringTrim value
stringLength value
stringCutAfter sep text
stringCutBefore sep text
- $COLOR_CLR
- $COLOR_RESET
- $COLOR_TXT
- $COLOR_ERR
- $COLOR_DONE
- $COLOR_INFO
- $COLOR_WARN
- $COLOR_VERBOSE
- $COLOR_VAR
colorize color ...text
colorRemove ...text
gitIsCurrentBranch name
gitSwitchBranch name
timeParse value
- value — ex.:
2s
,5m
,24h
or5d
log level ...msg
- level — msg, ok, done, info, warn, err, verbose
logMsg ...msg
logErr ...msg
logDone ...msg
logWarn ...msg
logInfo ...msg
logVerbose ...msg
hrLine ...msg
logHead text
logFinish [status] [done=DONE] [failed=FAILED]
default val
required val errMsg
assignVar ref val
getArg name
RE pattern forSED
range from to
md5hash value
- $PKG_JSON_RAW
- $PKG_JSON_NAME
- $PKG_JSON_VERSION
- $PKG_JSON_DESCRIPTION
- $PKG_JSON_AUTHOR
- $PKG_JSON_MAIN
- $PKG_JSON_GIT_URL
- $PKG_JSON_DEPS_HASH
pkgJsonRead path
pkgJsonReadProp raw prop
- raw — a result of
pkgJsonRead
execute cmd [ref-status]
- [ref-status] — execution result status,
$EXEC_OK
— success, else failed
executeStatus code
executeIf cond cmd [ref-status]
- cond — $Y/$EXEC_OK or $N
- [ref-status] — execution result status,
$EXEC_OK
— success, else failed
executeIfNot cond cmd
- cond — $Y/$EXEC_OK or $N
emojiStatus [name=done]
- [name=done] —
ok
,err
ordone
recently name period ...fn
- period — ex:
5m
,24h
or7d