From e615a2d36b6fa97db09ac1dfc3e2dd37216ad844 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 30 Nov 2021 11:01:17 -0500 Subject: [PATCH] Create a grub-list.zsh command For listing the available kernels on the current machine Signed-off-by: Anna Schumaker --- completions/_grub-list.zsh | 7 +++++++ grub-list.zsh | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 completions/_grub-list.zsh create mode 100755 grub-list.zsh diff --git a/completions/_grub-list.zsh b/completions/_grub-list.zsh new file mode 100644 index 0000000..19f19d0 --- /dev/null +++ b/completions/_grub-list.zsh @@ -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]' +} diff --git a/grub-list.zsh b/grub-list.zsh new file mode 100755 index 0000000..709ba26 --- /dev/null +++ b/grub-list.zsh @@ -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