Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. colorize() {
  4.     case "$1" in
  5.         red)
  6.             local color_start=$(tput setaf 1);;
  7.         green)
  8.             local color_start=$(tput setaf 2);;
  9.         yellow)
  10.             local color_start=$(tput setaf 3);;
  11.         blue)
  12.             local color_start=$(tput setaf 4);;
  13.         purple)
  14.             local color_start=$(tput setaf 5);;
  15.         cyan)
  16.             local color_start=$(tput setaf 6);;
  17.     esac
  18.  
  19.     shift
  20.     local color_reset='\033[0m'
  21.  
  22.     echo "${color_start}$*${color_reset}"
  23. }
  24.  
  25. rnd_color() {
  26.     arr=('red' 'green' 'yellow' 'blue' 'purple' 'cyan')
  27.     printf "${arr[RANDOM % 6]}"
  28. }
  29.  
  30. analysis() {
  31.     sent="$1"
  32.     re="$(printf "$sent" | tr -cs "[:alpha:]" "\n" | sed 's/^\(.\).*/\1/' | uniq -di)"
  33.    
  34.     if [ -z "$re" ]; then
  35.         return
  36.     fi
  37.  
  38.     while read -r smb; do
  39.         smb_l=$(printf "$smb" | tr '[:upper:]' '[:lower:]')
  40.         smb_u=$(printf "$smb" | tr '[:lower:]' '[:upper:]')
  41.         color=$(rnd_color)
  42.         color_smb=" $(colorize $color "$smb_l")"
  43.         sent="${sent// "$smb_l"/$color_smb}"
  44.         color_smb="-$(colorize $color "$smb_l")"
  45.         sent="${sent//-"$smb_l"/$color_smb}"
  46.         color_smb=" $(colorize $color "$smb_u")"
  47.         sent="${sent// "$smb_u"/$color_smb}"
  48.         color_smb="-$(colorize $color "$smb_u")"
  49.         sent="${sent//-"$smb_u"/$color_smb}"
  50.     done <<<"$re"
  51.    
  52.     printf "$sent\n"
  53. }
  54.  
  55. while read -r line; do
  56.     analysis "$line"
  57. done <<<"$(cat -- "${1--}" | sed 's/\.\.\./…/g;s/\?\!/‽/g;s/[.…‽!?]/&\
  58. /g;s/^[ \t]*//;s/[ \t]*$//;/^$/d')"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement