diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-03-26 12:31:53 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-03-26 16:37:50 +0100 |
commit | 71a5350b681e022e9738b50f2977ddb529110bfb (patch) | |
tree | 4c199980a9f80c07d69130a72402a5cfe2a8a63f /sway/commands.c | |
parent | 3da269b78a3798f69b34b2515c7d9212e0e6827f (diff) |
Implement include command
The include command (`include <path>`) makes it possible to include sub
config files from the main config file (or from within other sub config
files).
The include command uses the following rules for including config files:
* the `path` can be either a full path or a path that is relative to the
parent config. Shell expansion is supported, so it's possible to do
`include ~/.config/sway.d/*`.
* The same config file can only be included once (to prevent include
cycles). If a config is included multiple times it will just be
ignored after it has been included once.
* Including a sub config file is the same as inserting the content of
that file into the parent config, thus rules about overwriting
bindsyms etc. works the same as for a single config.
Implement #542
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c index 26fa771e..bc8c42eb 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -55,6 +55,7 @@ static sway_cmd cmd_font; static sway_cmd cmd_for_window; static sway_cmd cmd_fullscreen; static sway_cmd cmd_gaps; +static sway_cmd cmd_include; static sway_cmd cmd_input; static sway_cmd cmd_kill; static sway_cmd cmd_layout; @@ -1141,6 +1142,19 @@ static struct cmd_results *input_cmd_tap(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *cmd_include(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "include", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (!load_include_configs(argv[0], config)) { + return cmd_results_new(CMD_INVALID, "include", "Failed to include sub configuration file: %s", argv[0]); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *cmd_input(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { @@ -1541,7 +1555,7 @@ static struct cmd_results *cmd_reload(int argc, char **argv) { if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { return error; } - if (!load_config(NULL)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); + if (!load_main_config(NULL, true)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); load_swaybars(); @@ -2053,6 +2067,7 @@ static struct cmd_handler handlers[] = { { "for_window", cmd_for_window }, { "fullscreen", cmd_fullscreen }, { "gaps", cmd_gaps }, + { "include", cmd_include }, { "input", cmd_input }, { "kill", cmd_kill }, { "layout", cmd_layout }, |