Create a grub-list.zsh command

For listing the available kernels on the current machine

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2021-11-30 11:01:17 -05:00
parent 8a73ed3a61
commit e615a2d36b
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#compdef grub-list.zsh
function _grub-list.zsh() {
_arguments \
{-h,--help}'[print help text]' \
{-e,--entries-only}'[print entries without row numbers]'
}

19
grub-list.zsh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/zsh
cmd=$0
zparseopts e=entries -entries-only=entries h=help -help=help
if [ ! -z "$help" ]; then
echo "Usage: $0 [-h|--help] [-e|--entries-only]"
echo "List the available GRUB menu options."
echo " -e, --entries-only print menu entries without row numbers"
echo " -h, --help print this message and exit"
exit 0
fi
menuentries=$(sudo awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg)
if [ -z "$entries" ]; then
echo $menuentries | awk '{print " ", NR-1, " ", $0}'
else
echo $menuentries
fi