From c6c5a7186374ed3653a2dc2243f64bc27d98220d Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Sat, 3 Nov 2018 00:19:31 -0400 Subject: [PATCH] config: allow for inline to end of line comments Allows for the following syntax in the config: `command # the rest of this line is a comment` Example: `input * repeat_delay 200 # milliseconds` Note: The space before and after the `#` is mandatory otherwise the `#` will be seen as part of an argument (such as colors). If a `#` is needed as it's own argument, then it can be enclosed in quotes. For example, `bar bar-0 separator_symbol "#"`. --- sway/commands.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 4b86c2fa2..b8e1b2c22 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -415,7 +415,13 @@ struct cmd_results *config_command(char *exec) { free(command); // Strip quotes and unescape the string - for (int i = handler->handle == cmd_set ? 2 : 1; i < argc; ++i) { + int i; + for (i = handler->handle == cmd_set ? 2 : 1; i < argc; ++i) { + if (strcmp(argv[i], "#") == 0) { + wlr_log(WLR_DEBUG, "Inline comment detected at argv[%d]." + "Ignoring all further arguments.", i); + break; + } if (handler->handle != cmd_exec && handler->handle != cmd_exec_always && handler->handle != cmd_bindsym && handler->handle != cmd_bindcode @@ -427,7 +433,7 @@ struct cmd_results *config_command(char *exec) { } // Run command - results = handler->handle(argc - 1, argv + 1); + results = handler->handle(i - 1, argv + 1); cleanup: free_argv(argc, argv);