Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rofi Theme selector use only same @theme line if present and create if not. #168

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions script/rofi-theme-selector
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

############################################################################################################
Expand Down