Compare commits
10 commits
0f5b546cbb
...
1386f61c55
| Author | SHA1 | Date | |
|---|---|---|---|
| 1386f61c55 | |||
|
|
bc9adccdf4 | ||
|
|
6c19d9b812 | ||
|
|
8d8e409bf7 | ||
| 3b2efe15bc | |||
| eb904a2059 | |||
| dd97cb372f | |||
| aa92dda307 | |||
| 0a23684b82 | |||
| 24715e6867 |
3 changed files with 127 additions and 28 deletions
88
README.org
88
README.org
File diff suppressed because one or more lines are too long
32
examples/clear
Executable file
32
examples/clear
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ----------------------
|
||||
# sf -- script framework
|
||||
# ----------------------
|
||||
|
||||
# Declare sf variables
|
||||
sfdesc="Show the usage of color variables and \$sftclr."
|
||||
|
||||
# Include sf, this could be replaced with a long oneliner
|
||||
source "$(dirname $0)/../sf"
|
||||
|
||||
# ----------------------
|
||||
# Actual script
|
||||
# ----------------------
|
||||
|
||||
echo -n "${sftbf}" # Output everything from here bold
|
||||
echo "${sftr}These" # Red
|
||||
sleep 0.5
|
||||
echo "${sftm}lines" # Magenta
|
||||
sleep 0.5
|
||||
echo "${sftb}will" # Blue
|
||||
sleep 0.5
|
||||
echo "${sftc}delete" # Cyan
|
||||
sleep 0.5
|
||||
echo "${sftg}themselves" # Green
|
||||
sleep 1
|
||||
echo "${sfty}now!" # Yellow
|
||||
sleep 0.5
|
||||
echo -n "${sftclr}${sftclr}${sftclr}${sftclr}${sftclr}${sftclr}" # Clear six lines
|
||||
echo "${sftblk}${sftr}T${sftm}a${sftb}d${sftc}a${sftg}a${sfty}!" # Blinking colorful
|
||||
echo -n "${sftrs}" # Reset text formatting
|
||||
35
sf
35
sf
|
|
@ -9,7 +9,7 @@ sftdim=$'\e[2m'
|
|||
sftul=$'\e[4m'
|
||||
sftblk=$'\e[5m'
|
||||
sftinv=$'\e[7m'
|
||||
sfthd=$'\e[8m'
|
||||
sfthdn=$'\e[8m'
|
||||
sftclr=$'\e[1A\e[K'
|
||||
sftk=$'\e[30m'
|
||||
sftr=$'\e[31m'
|
||||
|
|
@ -22,21 +22,23 @@ sftw=$'\e[97m'
|
|||
|
||||
# Public output functions
|
||||
function sferr {
|
||||
echo "${sftbf}${sftr}ERROR${sftrs} $1"
|
||||
echo -e "${sftbf}${sftr}ERROR${sftrs} $1"
|
||||
[ -z "$2" ] && exit 1
|
||||
}
|
||||
|
||||
function sfwarn {
|
||||
echo "${sftbf}${sfty}WARNING${sftrs} $1"
|
||||
echo -e "${sftbf}${sfty}WARNING${sftrs} $1"
|
||||
}
|
||||
|
||||
# Public input functions
|
||||
function sfask {
|
||||
if [ -n "$2" ]; then
|
||||
read -r -p "$1? [${sftbf}y${sftrs}/${sftbf}N${sftrs}] " sfin
|
||||
echo -ne "$1? [${sftbf}y${sftrs}/${sftbf}N${sftrs}] "
|
||||
read -r sfin
|
||||
[[ "$sfin" =~ n|N|^$ ]] && sfin=false || sfin=true
|
||||
else
|
||||
read -r -p "$1? [${sftbf}Y${sftrs}/${sftbf}n${sftrs}] " sfin
|
||||
echo -ne "$1? [${sftbf}Y${sftrs}/${sftbf}n${sftrs}] "
|
||||
read -r sfin
|
||||
[[ "$sfin" =~ y|Y|^$ ]] && sfin=true || sfin=false
|
||||
fi
|
||||
}
|
||||
|
|
@ -76,7 +78,7 @@ for a in "${sfargs[@]}"; do
|
|||
|
||||
# Get amount of semicolons
|
||||
_sfsubst=${a//";"}
|
||||
_sfcount="$(((${#a} - ${#_sfsubst})))"
|
||||
_sfcount="$(( ${#a} - ${#_sfsubst} ))"
|
||||
|
||||
# Positional arguments
|
||||
if [ "$_sfcount" -eq 1 ]; then
|
||||
|
|
@ -150,7 +152,7 @@ for e in "${sfexamples[@]}"; do
|
|||
|
||||
# Get amount of ;
|
||||
_sfsubst=${e//";"}
|
||||
_sfcount="$(((${#e} - ${#_sfsubst})))"
|
||||
_sfcount="$(( ${#e} - ${#_sfsubst} ))"
|
||||
|
||||
if [ "$_sfcount" -eq 1 ]; then
|
||||
|
||||
|
|
@ -173,6 +175,9 @@ IFS=$OLDIFS
|
|||
# Check if at least one positional argument is set if 'sfparr' is used
|
||||
[ "$sfparr" == true ] && [ "${#_sfpargs[@]}" == 0 ] && _sferr "At least one positional argument must be used with ${sftbf}sfparr${sftrs}"
|
||||
|
||||
# Correct positional argument description if 'sfparr' is used
|
||||
[ "$sfparr" == true ] && _sfpusage="${_sfpusage% *} [${_sfpusage##* } ...]"
|
||||
|
||||
# Correct offsets
|
||||
_sfpoffset=$(( "_sfpoffset" + 3 ))
|
||||
_sfooffset=$(( "_sfooffset" + 3 ))
|
||||
|
|
@ -224,24 +229,21 @@ done
|
|||
function _sfusage {
|
||||
echo -n "Usage: $(basename "$0") [OPTIONS]"
|
||||
echo -ne "$_sfpusage"
|
||||
[ "$sfparr" == true ] && echo -n " ..."
|
||||
echo
|
||||
[ -n "${sfdesc}" ] && echo -e "\n$sfdesc" | fold -s -w "$_sfwidth"
|
||||
if [ "$_sfpdesc" != "" ]; then
|
||||
echo -e "\nPOSITIONAL ARGUMENTS"
|
||||
echo -e "$_sfpdesc" | column -s ";" -t -W 2
|
||||
echo -e "$_sfpdesc" | column -s ";" -t
|
||||
fi
|
||||
if [ "$_sfodesc" != "" ]; then
|
||||
echo -e "\nOPTIONS"
|
||||
echo -e "$_sfodesc" | column -s ";" -t -W 2
|
||||
echo -e "$_sfodesc" | column -s ";" -t
|
||||
fi
|
||||
if [ "$_sfexamples" != "" ]; then
|
||||
echo -e "\nEXAMPLES"
|
||||
echo -e "$_sfexamples" | column -s ";" -t -W 2
|
||||
fi
|
||||
if [ -n "${sfextra}" ]; then
|
||||
echo -e "\n$sfextra"
|
||||
echo -e "$_sfexamples" | column -s ";" -t
|
||||
fi
|
||||
[ -n "${sfextra}" ] && echo -e "\n$sfextra" | fold -s -w "$_sfwidth"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +284,7 @@ while (( "$#" )); do
|
|||
else
|
||||
# Check if arg starts with -
|
||||
if [ "${1:0:1}" == "-" ]; then
|
||||
sferr "Unsupported argument/flag: ${sftbf}${1}${sftrs}"
|
||||
sferr "Unsupported argument/flag ${sftbf}${1}${sftrs}"
|
||||
else
|
||||
# Set positional argument
|
||||
if [ "${#_sfpargs[@]}" != 0 ]; then
|
||||
|
|
@ -302,6 +304,9 @@ done
|
|||
# Parse additional arguments if 'sfparr' is set
|
||||
[ "$sfparr" == true ] && [ "${#_sfparr[@]}" -gt 0 ] && read -r -a "${_sfplast?}" <<< "${_sfparr[@]}"
|
||||
|
||||
# Remove last missing argument to allow empty arrays if 'sfparr' is set
|
||||
[ "$sfparr" == true ] && [ "${#_sfpargs[@]}" -gt 0 ] && unset '_sfpargs[${#_sfpargs[@]}-1]'
|
||||
|
||||
# Check if positional arguments left
|
||||
if [ "${#_sfpargs[@]}" -gt 0 ]; then
|
||||
for p in "${_sfpargs[@]}"; do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue