add cmd_env to set environment variables at config and runtime

This commit is contained in:
slonkazoid 2024-09-03 17:02:47 +03:00
parent be840f730e
commit 27d27dd121
No known key found for this signature in database
4 changed files with 17 additions and 0 deletions

View file

@ -125,6 +125,7 @@ sway_cmd cmd_create_output;
sway_cmd cmd_default_border;
sway_cmd cmd_default_floating_border;
sway_cmd cmd_default_orientation;
sway_cmd cmd_env;
sway_cmd cmd_exec;
sway_cmd cmd_exec_always;
sway_cmd cmd_exit;

View file

@ -57,6 +57,7 @@ static const struct cmd_handler handlers[] = {
{ "client.urgent", cmd_client_urgent },
{ "default_border", cmd_default_border },
{ "default_floating_border", cmd_default_floating_border },
{ "env", cmd_env },
{ "exec", cmd_exec },
{ "exec_always", cmd_exec_always },
{ "floating_maximum_size", cmd_floating_maximum_size },

14
sway/commands/env.c Normal file
View file

@ -0,0 +1,14 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include "sway/commands.h"
struct cmd_results *cmd_env(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "env", EXPECTED_EQUAL_TO, 2))) {
return error;
}
setenv(argv[0], argv[1], 1);
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

@ -52,6 +52,7 @@ sway_sources = files(
'commands/default_border.c',
'commands/default_floating_border.c',
'commands/default_orientation.c',
'commands/env.c',
'commands/exit.c',
'commands/exec.c',
'commands/exec_always.c',