: ' Changes
Fri Feb 21 2025 Changed select characters for better terminal support
Sat Feb 15 2025 Changed system for random character
Sat Feb 15 2025 Added in version feature
Sat Feb 15 2025 Added random color
'
[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
DOW=$(date +%a)
TODAY=$(date +%m/%d)
DOM=$(date +%d)
OS=$(uname -s)
NAME=${0##*/}
my_string="+=-#:~βββπΈπΆππ΄π€π£π‘π΅π’γ°π
β¬π³ππ₯π§Ώπ "
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
BC=$(tput setaf 6; tput bold)
C=$(tput setaf 6)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
RV=$(tput rev)
ROWS=$(tput lines)
COLS=$(tput cols)
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
center(){
[ "$DEBUG" == "1" ] && set -x
[[ $# == 0 ]] && return 1;
declare -i TERM_COLS="$(tput cols)";
declare -i str_len="${#1}";
[[ $str_len -ge $TERM_COLS ]] && {
echo "$1";
return 0
};
declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))";
[[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" ";
filler="";
for ((i = 0; i < filler_len; i++ ))
do
filler="${filler}${ch}";
done;
printf "%s%s%s" "$filler" "$1" "$filler";
[[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}";
printf "\n";
return 0
}
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
pause(){
[ "$DEBUG" == "1" ] && set -x
[ "$1" == "-nt" ] && TMOUT="" && shift
echo "$BY";
if [ $# -gt 0 ]
then
read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
else
read -r -p "${C}Hit any key${N}" -n 1 FOO;
fi;
bl
}
rcf ()
{
tput setaf $((RANDOM % 256))
}
strip-tags(){
sed -e 's/<[^>]*.//g' -
}
xtitle(){
printf "\033]0;%s\007" "$*"
}
version(){
grep -E '^# Updated' $0
bl
sed -n "/' Changes/,/^ *$/p" <$0 |grep -E -v 'sed -n|exit 0|}'
exit 0
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
${BC}$NAME${N} {string} {count}
Draw a simple line terminal width:
$(line)
Options:
{string} is the characters you want to use
{count} is the number of iterations
- If no count is given then terminal width is used.
- If no character is given then a random one is used.
Use: line "=" (Create line of "=" terminal wide)
line "-+" 20 (Create line of "-+" 20 characters wide)
-v # ${BY}Display version and change history${N}
END
exit
fi
if [ "$1" == "-v" ] || [ "$1" == "--version" ]
then
version
fi
command -v bash >/dev/null || sudo apt install bash -qyy
[ "$DEBUG" == 1 ] && set -x
if [ "$#" -eq 0 ]
then
string_length=${#my_string}
random_index=$((RANDOM % string_length))
ASCII="${my_string:$random_index:1}"
else
ASCII="$1"
fi
CHAR=$(echo -n "$ASCII" |wc -c)
CNT="${2:-$(tput cols)}"
[ "$CHAR" -gt 1 ] && CNT=$(($CNT/2))
rcf
until [ $CNT -eq 0 ]
do
echo -n "$ASCII"
CNT=$(($CNT - 1))
done
echo "$N"