dm-change-alacritty-colors.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. # Colors:
  3. # Materia Manjaro
  4. nf='#09dbc9'
  5. nb='#222b2e'
  6. sf='#dbdcd5'
  7. sb='#009185'
  8. fn='Ubuntu-16:normal'
  9. # Gruvbox
  10. # nf='#fea63c'
  11. # nb='#282828'
  12. # # sf='#dbdcd5'
  13. # sb='#d79921'
  14. # fn='Sarasa Mono SC Nerd-17:normal'
  15. is_color_exists() {
  16. for c in "${color_files[@]}"
  17. do
  18. if [[ "$1" == "${c}" ]]
  19. then
  20. echo "true"
  21. return
  22. fi
  23. done
  24. echo "false"
  25. }
  26. if [[ -n $WAYLAND_DISPLAY ]]; then
  27. DMENU=dmenu-wl
  28. xdotool="ydotool type --file -"
  29. elif [[ -n $DISPLAY ]]; then
  30. DMENU="dmenu -i -l 10 -nf ${nf} -nb ${nb} -sf ${sf} -sb ${sb} -fn ${fn} -p"
  31. xdotool="xdotool type --clearmodifiers --file -"
  32. else
  33. echo "Error: No Wayland or X11 display detected" >&2
  34. exit 1
  35. fi
  36. is_color_exists=0
  37. config_file=${CONFIG_STORE_DIR-~/.config/alacritty/alacritty.toml}
  38. prefix=${COLORS_STORE_DIR-~/.config/alacritty/colors}
  39. color_files=("$prefix"/*.toml)
  40. color_files=("${color_files[@]#"$prefix"/}")
  41. color_files=("${color_files[@]%.toml}")
  42. # color=$(printf '%s\n' "${color_files[@]}" | "$dmenu" -i -l 10 -nf ${nf} -nb ${nb} -sf ${sf} -sb ${sb} -fn ${fn} -p 'Alacritty colors you want:')
  43. color=$(printf '%s\n' "${color_files[@]}" | ${DMENU} 'Alacritty colors you want:')
  44. [[ -n ${color} ]] || exit
  45. is_color=$(is_color_exists ${color})
  46. if [[ ${is_color} == "true" ]]
  47. then
  48. # import = ["/home/alexander/.config/alacritty/colors/Ayu-Mirage-Dark.toml"]
  49. # old_line=$(grep "\- ~/.config/alacritty/colors/" ${config_file})
  50. # new_line=" - ~/.config/alacritty/colors/"${color}".toml"
  51. old_line=$(grep "import" ${config_file} | awk -F/ '{print $NF}' | cut -d'"' -f1)
  52. new_line="${color}.toml"
  53. sed -i "s|${old_line}|${new_line}|" ${config_file}
  54. notify-send -t 5000 -i dialog-information "Colors" "changed to ${color}"
  55. else
  56. notify-send -t 5000 -i dialog-information "Colors" "${color} doesn't exist."
  57. fi