From 53e08772f72040bb97f38f0a58d7f5e19ec0c4d6 Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Fri, 7 Feb 2025 18:45:18 +0900 Subject: [PATCH 1/2] this should fix https://github.com/lbonn/rofi/issues/167 --- script/rofi-theme-selector | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/script/rofi-theme-selector b/script/rofi-theme-selector index 99eb6ac1e..e0d1a3653 100755 --- a/script/rofi-theme-selector +++ b/script/rofi-theme-selector @@ -199,9 +199,12 @@ 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}" + # Replace existing @theme line with the new selected theme path, or add it if it doesn't exist + if grep -q '^\s*@theme' "${get_link}"; then + ${SED} -i "s|^\s*@theme.*|@theme \"${1}\"|" "${get_link}" + else + echo -e "\n@theme \"${1}\"" >> "${get_link}" + fi } ############################################################################################################ From f39596a50978efcc29e19d122d6390f76596d46b Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Sat, 8 Feb 2025 13:51:22 +0900 Subject: [PATCH 2/2] limiting the //@theme line to 9 lines with 10th line as current --- script/rofi-theme-selector | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/script/rofi-theme-selector b/script/rofi-theme-selector index e0d1a3653..a8fceb7e9 100755 --- a/script/rofi-theme-selector +++ b/script/rofi-theme-selector @@ -199,12 +199,24 @@ set_theme() touch "${get_link}" fi - # Replace existing @theme line with the new selected theme path, or add it if it doesn't exist - if grep -q '^\s*@theme' "${get_link}"; then - ${SED} -i "s|^\s*@theme.*|@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 - echo -e "\n@theme \"${1}\"" >> "${get_link}" + ${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 } ############################################################################################################