From d9ef569fe4bb0fdd7f59d9fba671448343e3e976 Mon Sep 17 00:00:00 2001 From: Denis Doria Date: Tue, 7 Jun 2016 11:10:52 +0200 Subject: [PATCH 1/2] Creates setenv command This allows to set environment variables for sway session. --- sway/commands.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index eab4a1c1b..0c614b89c 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -85,6 +85,7 @@ static sway_cmd cmd_reload; static sway_cmd cmd_resize; static sway_cmd cmd_scratchpad; static sway_cmd cmd_set; +static sway_cmd cmd_setenv; static sway_cmd cmd_smart_gaps; static sway_cmd cmd_split; static sway_cmd cmd_splith; @@ -2188,6 +2189,29 @@ static struct cmd_results *cmd_set(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +/** +* Set environment variables for sway session +**/ +static struct cmd_results *cmd_setenv(int argc, char **argv) { + int env; + struct cmd_results *error = NULL; + + if ((error = checkarg(argc, "setenv", EXPECTED_AT_LEAST, 2))) { + return error; + } + + if (argv[0][0] == '$') { + memmove(argv[0], argv[0]+1, strlen(argv[0])); + } + + env = setenv(argv[0], argv[1], 1); + if (env == -1) { + return cmd_results_new(CMD_FAILURE, "setenv", "Variable name contains '=' or has size 0."); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *_do_split(int argc, char **argv, int layout) { char *name = layout == L_VERT ? "splitv" : layout == L_HORIZ ? "splith" : "split"; @@ -2544,6 +2568,7 @@ static struct cmd_handler handlers[] = { { "scratchpad", cmd_scratchpad }, { "seamless_mouse", cmd_seamless_mouse }, { "set", cmd_set }, + { "setenv", cmd_setenv }, { "smart_gaps", cmd_smart_gaps }, { "split", cmd_split }, { "splith", cmd_splith }, From 6fefe56a9723b6c296f0a74a5b2dce035f146cfe Mon Sep 17 00:00:00 2001 From: Denis Doria Date: Tue, 7 Jun 2016 11:13:42 +0200 Subject: [PATCH 2/2] Manual entry for setenv --- sway/sway.5.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 397b6d873..199d70b00 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -46,6 +46,9 @@ The following commands may only be used in the configuration file. Creates a substitution for _value_ that can be used with $_name_ in other commands. +**setenv** :: + Creates an environment variable that can be used during sway session. + The following commands cannot be used directly in the configuration file. They are expected to be used with **bindsym** or at runtime through **swaymsg**(1).