KhaledEmaraDev

pywal.sh

Jan 26th, 2021
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Color files
  4. PFILE="$HOME/.config/polybar/colors.ini"
  5. RFILE="$HOME/.config/polybar/scripts/rofi/colors.rasi"
  6.  
  7. # Get colors
  8. pywal_get() {
  9. wal -i "$1" -q -t
  10. }
  11.  
  12. # Change colors
  13. change_color() {
  14. # polybar
  15. sed -i -e "s/background = #.*/background = #CC$BG/g" $PFILE
  16. sed -i -e "s/foreground = #.*/foreground = $FG/g" $PFILE
  17. sed -i -e "s/sep = #.*/sep = $FGA/g" $PFILE
  18.  
  19. # rofi
  20. cat > $RFILE <<- EOF
  21. /* colors */
  22.  
  23. * {
  24. al: #00000000;
  25. bg: #${BG}CC;
  26. bga: ${AC}33;
  27. se: ${MF}FF;
  28. fg: ${FG}FF;
  29. ac: ${AC}FF;
  30. }
  31. EOF
  32. }
  33.  
  34. hex_to_rgb() {
  35. # Convert a hex value WITHOUT the hashtag (#)
  36. R=$(printf "%d" 0x${1:0:2})
  37. G=$(printf "%d" 0x${1:2:2})
  38. B=$(printf "%d" 0x${1:4:2})
  39. }
  40.  
  41. get_fg_color(){
  42. INTENSITY=$(calc "$R*0.299 + $G*0.587 + $B*0.114")
  43.  
  44. if [ $(echo "$INTENSITY>186" | bc) -eq 1 ]; then
  45. MF="#202020"
  46. else
  47. MF="#F5F5F5"
  48. fi
  49. }
  50.  
  51. # Main
  52. if [[ -f "/usr/bin/wal" ]]; then
  53. if [[ "$1" ]]; then
  54. pywal_get "$1"
  55.  
  56. # Source the pywal color file
  57. . "$HOME/.cache/wal/colors.sh"
  58.  
  59. BG=`printf "%s\n" "${background:1}"`
  60. FG=`printf "%s\n" "$foreground"`
  61. FGA=`printf "%s\n" "$color8"`
  62. AC=`printf "%s\n" "$color1"`
  63. SC=`printf "%s\n" "$color2"`
  64. AL=`printf "%s\n" "$color3"`
  65.  
  66. HEX=${AC:1}
  67.  
  68. hex_to_rgb $HEX
  69. get_fg_color
  70. change_color
  71. else
  72. echo -e "[!] Please enter the path to wallpaper. \n"
  73. echo "Usage : ./pywal.sh path/to/image"
  74. fi
  75. else
  76. echo "[!] 'pywal' is not installed."
  77. fi
  78.  
Advertisement
Add Comment
Please, Sign In to add comment