Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- colorize() {
- case "$1" in
- red)
- local color_start=$(tput setaf 1);;
- green)
- local color_start=$(tput setaf 2);;
- yellow)
- local color_start=$(tput setaf 3);;
- blue)
- local color_start=$(tput setaf 4);;
- purple)
- local color_start=$(tput setaf 5);;
- cyan)
- local color_start=$(tput setaf 6);;
- esac
- shift
- local color_reset='\033[0m'
- echo "${color_start}$*${color_reset}"
- }
- rnd_color() {
- arr=('red' 'green' 'yellow' 'blue' 'purple' 'cyan')
- printf "${arr[RANDOM % 6]}"
- }
- analysis() {
- sent="$1"
- re="$(printf "$sent" | tr -cs "[:alpha:]" "\n" | sed 's/^\(.\).*/\1/' | uniq -di)"
- if [ -z "$re" ]; then
- return
- fi
- while read -r smb; do
- smb_l=$(printf "$smb" | tr '[:upper:]' '[:lower:]')
- smb_u=$(printf "$smb" | tr '[:lower:]' '[:upper:]')
- color=$(rnd_color)
- color_smb=" $(colorize $color "$smb_l")"
- sent="${sent// "$smb_l"/$color_smb}"
- color_smb="-$(colorize $color "$smb_l")"
- sent="${sent//-"$smb_l"/$color_smb}"
- color_smb=" $(colorize $color "$smb_u")"
- sent="${sent// "$smb_u"/$color_smb}"
- color_smb="-$(colorize $color "$smb_u")"
- sent="${sent//-"$smb_u"/$color_smb}"
- done <<<"$re"
- printf "$sent\n"
- }
- while read -r line; do
- analysis "$line"
- done <<<"$(cat -- "${1--}" | sed 's/\.\.\./…/g;s/\?\!/‽/g;s/[.…‽!?]/&\
- /g;s/^[ \t]*//;s/[ \t]*$//;/^$/d')"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement