Advertisement
cpt-alatriste

Dovlatizer

Aug 19th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.54 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="$(echo "$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=$(echo "$smb" | tr '[:upper:]' '[:lower:]')
  40.         smb_u=$(echo "$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.         color_smb="\
  51. $(colorize $color "$smb_u")"
  52.         sent="${sent//\
  53. "$smb_u"/$color_smb}"
  54.     done <<<"$re"
  55.    
  56.     echo -e "$sent"
  57. }
  58.  
  59. while read -r line; do
  60.     analysis "$line"
  61. done <<<"$(cat -- "${1--}" | sed 's/\.\.\./…/g;s/\?\!/‽/g;s/[.…‽!?]/&\
  62. /g;s/^[ \t]*//;s/[ \t]*$//;/^$/d')"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement