Create a list for every line in a text file

143 views
Skip to first unread message

egonol...@gmail.com

unread,
Sep 8, 2021, 10:15:21 AM9/8/21
to yad-common

Hi,

i use grub-reboot so set an other OS for the next boot. I want to create a little menu where i can select one of the other OS. I read that information from /boot/grub/grub.cfg, at the end i have a list like this:

Ubuntu
Ubuntu 20.04.3 LTS (20.04) (auf /dev/sda2)
Windows Boot Manager (auf /dev/sdb2)
Ubuntu 20.04.2 LTS (20.04) (auf /dev/sdf2)
UEFI Firmware Settings


How can i create a list with yad depending on the number of entries in the file. When i delete one of the OS and update the grub.cfg the yad menu should have one line less.

Милош Павловић

unread,
Sep 8, 2021, 4:53:52 PM9/8/21
to yad-common
Pipe to yad, every line will be a new row.
To show the submenu from grub  .cfg the second example will do, requires new(er) yad with --tree option.

#!/bin/bash

awk -F\' '/menuentry / {print $2 }' /boot/grub/grub.cfg \
| yad --width=500 --height=400 --listen --list --separator="" \
--column="GRUB Menu Entry"


awk -F\' '$1=="menuentry " || $1=="submenu " {print 1+i++ "\n" $2 };
/\tmenuentry / {print  1+i+j++":" i "\n" $2 };' /boot/grub/grub.cfg \
| yad --width=500 --height=400 --listen --list --separator="" \
--tree --tree-expanded --column="GRUB Menu Entry"

egonol...@gmail.com

unread,
Sep 24, 2021, 9:09:43 AM9/24/21
to yad-common
works, thanks.
Reply all
Reply to author
Forward
0 new messages