diff --git a/script/rofi-theme-selector b/script/rofi-theme-selector index 99eb6ac1e..a8fceb7e9 100755 --- a/script/rofi-theme-selector +++ b/script/rofi-theme-selector @@ -199,9 +199,24 @@ set_theme() touch "${get_link}" fi - # Comment old base theme, not replace as it may be modified after the line - ${SED} -i '/^\s*@theme/ s,^,//,' "${get_link}" - echo -e "\n@theme \"${1}\"" >> "${get_link}" + # If no @theme is in the file, add it + if ! grep -q '^\s*@theme' "${get_link}"; then + echo -e "\n\n@theme \"${1}\"" >> "${get_link}" + else + ${SED} -i "s/^\(\s*@theme.*\)/\/\/\1/" "${get_link}" + echo -e "@theme \"${1}\"" >> "${get_link}" + fi + # Ensure no more than # of lines with //@theme lines + max_line="9" + total_lines=$(grep -c '^\s*//@theme' "${get_link}") + + if [ "$total_lines" -gt $max_line ]; then + excess=$(($total_lines - $max_line)) + # Remove the oldest or the very top //@theme + for i in $(seq 1 $excess); do + ${SED} -i '0,/^\s*\/\/@theme/ { /^\s*\/\/@theme/ {d; q; }}' "${get_link}" + done + fi } ############################################################################################################