From ff5a7425d0eb595bc68f055ccd0e9eaceed8351d Mon Sep 17 00:00:00 2001
From: livio <livio@codeberg.org>
Date: Sat, 30 Mar 2024 23:36:22 +0100
Subject: [PATCH] Improved GRUB directory listing by automatically filling from
 any possible (super/sub)directories

---
 config/grub/config/grub.cfg | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/config/grub/config/grub.cfg b/config/grub/config/grub.cfg
index d4c0677e..6c2e2fc8 100644
--- a/config/grub/config/grub.cfg
+++ b/config/grub/config/grub.cfg
@@ -136,12 +136,24 @@ menuentry "List all bootable medias" {
 	scan_l_media_menus
 }
 
-# FIXME Make an automatic override for BTRFS directories instead of copypasting with a "@/" in front of every element
-
 # Default list of GRUB possible directories. The @/... entries are for cases where the BTRFS filesystem is being used
-set grub_dirs="boot grub grub2 boot/grub boot/grub2 @/boot @/grub @/grub2 @/boot/grub @/boot/grub2"
+set grub_dirs="" # Complete list of every possible grub directory, automatically filled later
+set grub_dir_super="@" # Possible list of superdirectories (BTRFS can have those)
+set grub_dir="boot grub grub2" # First level directories list
+set grub_dir_sub="grub grub2" # Second level directories list
+
+for i in '' ${grub_dir_super}; do
+	grub_dirs="${grub_dirs} ${i}"
+	for j in ${grub_dir}; do
+		grub_dirs="${grub_dirs} ${i}/${j}"
+		for k in ${grub_dir_sub}; do
+			grub_dirs="${grub_dirs} ${i}/${j}/${k}"
+		done
+	done
+done
+
 # Default list of GRUB possible config files prefixes
-set grub_conf_names="'' osboot_ autoboot_ libreboot_ coreboot_"
+set grub_conf_names="osboot_ autoboot_ libreboot_ coreboot_"
 
 # Creates a menuentry for GRUB. First argument is menu text without spaces then root and configfile
 function grub_menuentry {
-- 
GitLab