All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
To: grub-devel@gnu.org
Cc: Adrien 'neox' Bourmault <neox@gnu.org>,
	Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Subject: [RFC][PATCH v1 2/4] Add command to append to existing environment variables.
Date: Sun, 30 Jun 2024 18:25:17 +0200	[thread overview]
Message-ID: <20240630162519.25173-3-GNUtoo@cyberdimension.org> (raw)
In-Reply-To: <20240630162519.25173-1-GNUtoo@cyberdimension.org>

This can be used to easily filter out the content of an environment
variable with multiple elements:

    for elm in $list ; do
        if regexp ^grub $elm ; then
           append results=" $elm"
        fi
    done

The goal is to use it to be able to be able to filter devices being
found once we add support for --set=VARNAME inside the ls command.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
---
 grub-core/kern/corecmd.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/grub-core/kern/corecmd.c b/grub-core/kern/corecmd.c
index 62d434ba9..88cf6e4d4 100644
--- a/grub-core/kern/corecmd.c
+++ b/grub-core/kern/corecmd.c
@@ -59,6 +59,28 @@ grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)),
   return 0;
 }
 
+/* Append VALUE to ENVVAR content */
+static grub_err_t
+grub_core_cmd_append (struct grub_command *cmd __attribute__ ((unused)),
+                      int argc, char *argv[])
+{
+  char *var;
+  char *val;
+
+  if (argc == 0)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+
+  var = argv[0];
+  val = grub_strchr (var, '=');
+  if (! val)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "not an assignment");
+
+  val[0] = 0;
+  grub_env_append (var, val + 1);
+
+  return 0;
+}
+
 static grub_err_t
 grub_core_cmd_unset (struct grub_command *cmd __attribute__ ((unused)),
 		     int argc, char *argv[])
@@ -182,6 +204,9 @@ grub_register_core_commands (void)
 			       N_("Set an environment variable."));
   if (cmd)
     cmd->flags |= GRUB_COMMAND_FLAG_EXTRACTOR;
+  grub_register_command ("append", grub_core_cmd_append,
+			 N_("[ENVVAR=VALUE]"),
+			 N_("Set an environment variable."));
   grub_register_command ("unset", grub_core_cmd_unset,
 			 N_("ENVVAR"),
 			 N_("Remove an environment variable."));
-- 
2.45.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  parent reply	other threads:[~2024-06-30 16:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-30 16:25 [RFC][PATCH v1 0/4] How to add --set=VARNAME to the ls command? Denis 'GNUtoo' Carikli
2024-06-30 16:25 ` [RFC][PATCH v1 1/4] Add grub_env_append function Denis 'GNUtoo' Carikli
2024-06-30 16:25 ` Denis 'GNUtoo' Carikli [this message]
2024-06-30 16:25 ` [RFC][PATCH v1 3/4] commands/ls: add --set=VARNAME Denis 'GNUtoo' Carikli
2024-06-30 16:25 ` [RFC][PATCH v1 4/4] commands/ls: support --set for files/directories Denis 'GNUtoo' Carikli
2024-06-30 17:05 ` [RFC][PATCH v1 0/4] How to add --set=VARNAME to the ls command? Vladimir 'phcoder' Serbinenko
2024-06-30 22:44   ` Denis 'GNUtoo' Carikli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240630162519.25173-3-GNUtoo@cyberdimension.org \
    --to=gnutoo@cyberdimension.org \
    --cc=grub-devel@gnu.org \
    --cc=neox@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.