simplifies title generation
This commit is contained in:
@@ -8,11 +8,10 @@ For readable progress report on any script with ease.
|
|||||||
|
|
||||||
Anotate your script with formatting helpers by using pipe construct
|
Anotate your script with formatting helpers by using pipe construct
|
||||||
|
|
||||||
*Example*
|
The header of your script
|
||||||
|
|
||||||
```
|
```
|
||||||
echo "Script title" | title
|
echo "Script title" | title
|
||||||
echo "Author: You" | subtitle
|
echo "Author: You" | title
|
||||||
```
|
```
|
||||||
|
|
||||||
Tasks are wrapped by the `section`, `output` and `result` helpers.
|
Tasks are wrapped by the `section`, `output` and `result` helpers.
|
||||||
@@ -20,7 +19,6 @@ The flow is :
|
|||||||
1. Print `section` header
|
1. Print `section` header
|
||||||
2. Use `output` helpers to display the output you want generated
|
2. Use `output` helpers to display the output you want generated
|
||||||
3. Close your section with `result`
|
3. Close your section with `result`
|
||||||
|
|
||||||
```
|
```
|
||||||
echo "Task number One" | section
|
echo "Task number One" | section
|
||||||
echo "This will work" | output::info
|
echo "This will work" | output::info
|
||||||
|
|||||||
40
main.sh
40
main.sh
@@ -6,26 +6,48 @@ error="$(tput setab 1)$(tput bold)"
|
|||||||
underline=$(tput smul)
|
underline=$(tput smul)
|
||||||
reset=$(tput sgr0)
|
reset=$(tput sgr0)
|
||||||
|
|
||||||
# Set pipefail option
|
export BOG_TITLE_PRINTED=0
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
title () {
|
# Set pipefail option
|
||||||
read title
|
# Exit status of overall pipe
|
||||||
echo " *************************************"
|
# instead of last one
|
||||||
|
set -o pipefail
|
||||||
|
# Avoid spawning subshell
|
||||||
|
# Needed for title to be able
|
||||||
|
# to be globally updated inside pipe
|
||||||
|
shopt -s lastpipe
|
||||||
|
|
||||||
|
__print_title_header () {
|
||||||
|
echo " *************************** "
|
||||||
|
echo " ********************************* "
|
||||||
echo " ****"
|
echo " ****"
|
||||||
echo "***** $title"
|
|
||||||
echo "*****"
|
echo "*****"
|
||||||
}
|
}
|
||||||
|
|
||||||
subtitle () {
|
__check_last_pipe_status () {
|
||||||
|
local last_index=$((${#PIPESTATUS[@]}-1))
|
||||||
|
local last_exit_code=${PIPESTATUS[$last_index]}
|
||||||
|
echo "DEBUG: $last_index, $last_exit_code"
|
||||||
|
return last_exit_code
|
||||||
|
}
|
||||||
|
|
||||||
|
title () {
|
||||||
|
if [[ $BOG_TITLE_PRINTED -eq 0 ]]
|
||||||
|
then
|
||||||
|
__print_title_header
|
||||||
|
BOG_TITLE_PRINTED=1
|
||||||
|
fi
|
||||||
|
|
||||||
read title
|
read title
|
||||||
echo "***** $title"
|
echo "***** $title"
|
||||||
}
|
}
|
||||||
|
|
||||||
footer () {
|
footer () {
|
||||||
echo "***** *****"
|
echo "***** *****"
|
||||||
echo "***** END OF SCRIPT *****"
|
echo "***** END OF SCRIPT *****"
|
||||||
echo " **** ****"
|
echo " **** **** "
|
||||||
|
echo " ********************************* "
|
||||||
|
echo " *********************** "
|
||||||
}
|
}
|
||||||
|
|
||||||
section () {
|
section () {
|
||||||
|
|||||||
Reference in New Issue
Block a user