Archlinux basic installation configuration scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.8 KiB

  1. #!/usr/bin/env bash
  2. # Color files
  3. PFILE="$HOME/.config/polybar/cuts/colors.ini"
  4. RFILE="$HOME/.config/polybar/cuts/scripts/rofi/colors.rasi"
  5. # Change colors
  6. change_color() {
  7. # polybar
  8. sed -i -e "s/background = #.*/background = #${BG}/g" $PFILE
  9. sed -i -e "s/background-alt = #.*/background-alt = #8C${BG}/g" $PFILE
  10. sed -i -e "s/foreground = #.*/foreground = #${FG}/g" $PFILE
  11. sed -i -e "s/foreground-alt = #.*/foreground-alt = #33${FG}/g" $PFILE
  12. sed -i -e "s/primary = #.*/primary = $AC/g" $PFILE
  13. # rofi
  14. cat > $RFILE <<- EOF
  15. /* colors */
  16. * {
  17. al: #00000000;
  18. bg: #${BG}BF;
  19. bga: #${BG}FF;
  20. fg: #${FG}FF;
  21. ac: ${AC}FF;
  22. se: ${AC}1A;
  23. }
  24. EOF
  25. polybar-msg cmd restart
  26. }
  27. get_random_number() {
  28. RNUM=$(( ($RANDOM % $1) + 1 ))
  29. }
  30. get_random_color() {
  31. RCOLOR="#"
  32. for i in 1 2 3 4 5 6
  33. do
  34. get_random_number "16"
  35. case $RNUM in
  36. "1") NEXTDIGIT="1";;
  37. "2") NEXTDIGIT="2";;
  38. "3") NEXTDIGIT="3";;
  39. "4") NEXTDIGIT="4";;
  40. "5") NEXTDIGIT="5";;
  41. "6") NEXTDIGIT="6";;
  42. "7") NEXTDIGIT="7";;
  43. "8") NEXTDIGIT="8";;
  44. "9") NEXTDIGIT="9";;
  45. "10") NEXTDIGIT="A";;
  46. "11") NEXTDIGIT="B";;
  47. "12") NEXTDIGIT="C";;
  48. "13") NEXTDIGIT="D";;
  49. "14") NEXTDIGIT="E";;
  50. "15") NEXTDIGIT="F";;
  51. "16") NEXTDIGIT="0";;
  52. esac
  53. RCOLOR="$RCOLOR$NEXTDIGIT"
  54. done
  55. echo $RCOLOR
  56. }
  57. hex_to_rgb() {
  58. # Convert a hex value WITHOUT the hashtag (#)
  59. R=$(printf "%d" 0x${1:0:2})
  60. G=$(printf "%d" 0x${1:2:2})
  61. B=$(printf "%d" 0x${1:4:2})
  62. }
  63. get_fg_color(){
  64. INTENSITY=$(calc "$R*0.299 + $G*0.587 + $B*0.114")
  65. if [ $(echo "$INTENSITY>186" | bc) -eq 1 ]; then
  66. FG="0a0a0a"
  67. AC="#0a0a0a"
  68. else
  69. FG="F5F5F5"
  70. AC="#F5F5F5"
  71. fi
  72. }
  73. # Main
  74. BGC=`get_random_color`
  75. BG=${BGC:1}
  76. HEX=$BG
  77. hex_to_rgb $HEX
  78. get_fg_color
  79. change_color