Compare commits
No commits in common. "1386f61c55fff5dc75f5c5c36b2a67a2b26ce494" and "0f5b546cbb7a4bb04b1745f8989bcd358f04cd20" have entirely different histories.
1386f61c55
...
0f5b546cbb
3 changed files with 28 additions and 127 deletions
80
README.org
80
README.org
File diff suppressed because one or more lines are too long
|
|
@ -1,32 +0,0 @@
|
|||
#!/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'
|
||||
sfthdn=$'\e[8m'
|
||||
sfthd=$'\e[8m'
|
||||
sftclr=$'\e[1A\e[K'
|
||||
sftk=$'\e[30m'
|
||||
sftr=$'\e[31m'
|
||||
|
|
@ -22,23 +22,21 @@ sftw=$'\e[97m'
|
|||
|
||||
# Public output functions
|
||||
function sferr {
|
||||
echo -e "${sftbf}${sftr}ERROR${sftrs} $1"
|
||||
echo "${sftbf}${sftr}ERROR${sftrs} $1"
|
||||
[ -z "$2" ] && exit 1
|
||||
}
|
||||
|
||||
function sfwarn {
|
||||
echo -e "${sftbf}${sfty}WARNING${sftrs} $1"
|
||||
echo "${sftbf}${sfty}WARNING${sftrs} $1"
|
||||
}
|
||||
|
||||
# Public input functions
|
||||
function sfask {
|
||||
if [ -n "$2" ]; then
|
||||
echo -ne "$1? [${sftbf}y${sftrs}/${sftbf}N${sftrs}] "
|
||||
read -r sfin
|
||||
read -r -p "$1? [${sftbf}y${sftrs}/${sftbf}N${sftrs}] " sfin
|
||||
[[ "$sfin" =~ n|N|^$ ]] && sfin=false || sfin=true
|
||||
else
|
||||
echo -ne "$1? [${sftbf}Y${sftrs}/${sftbf}n${sftrs}] "
|
||||
read -r sfin
|
||||
read -r -p "$1? [${sftbf}Y${sftrs}/${sftbf}n${sftrs}] " sfin
|
||||
[[ "$sfin" =~ y|Y|^$ ]] && sfin=true || sfin=false
|
||||
fi
|
||||
}
|
||||
|
|
@ -78,7 +76,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
|
||||
|
|
@ -152,7 +150,7 @@ for e in "${sfexamples[@]}"; do
|
|||
|
||||
# Get amount of ;
|
||||
_sfsubst=${e//";"}
|
||||
_sfcount="$(( ${#e} - ${#_sfsubst} ))"
|
||||
_sfcount="$(((${#e} - ${#_sfsubst})))"
|
||||
|
||||
if [ "$_sfcount" -eq 1 ]; then
|
||||
|
||||
|
|
@ -175,9 +173,6 @@ 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 ))
|
||||
|
|
@ -229,21 +224,24 @@ 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
|
||||
echo -e "$_sfpdesc" | column -s ";" -t -W 2
|
||||
fi
|
||||
if [ "$_sfodesc" != "" ]; then
|
||||
echo -e "\nOPTIONS"
|
||||
echo -e "$_sfodesc" | column -s ";" -t
|
||||
echo -e "$_sfodesc" | column -s ";" -t -W 2
|
||||
fi
|
||||
if [ "$_sfexamples" != "" ]; then
|
||||
echo -e "\nEXAMPLES"
|
||||
echo -e "$_sfexamples" | column -s ";" -t
|
||||
echo -e "$_sfexamples" | column -s ";" -t -W 2
|
||||
fi
|
||||
if [ -n "${sfextra}" ]; then
|
||||
echo -e "\n$sfextra"
|
||||
fi
|
||||
[ -n "${sfextra}" ] && echo -e "\n$sfextra" | fold -s -w "$_sfwidth"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
|
@ -284,7 +282,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
|
||||
|
|
@ -304,9 +302,6 @@ 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