[PATCH weston, v3] weston-terminal: Add cwd and command options
ahmet acar
oavc-fujie at yandex.com
Wed Sep 23 16:38:13 PDT 2015
Add 'cwd' (current working directory) and 'command' (run specified
command immediately after startup) switch to weston-terminal.
Both switch are optional.
v3:
-change command execution mechanism as 'bash -c command' (Bill Spitzak)
Running weston-terminal --command="nano main.c" equals below:
(quoting in above required if command contains space)
##weston.ini## (snipped)
[terminal]
command=nano main.c // it should not quoting
---
clients/terminal.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/clients/terminal.c b/clients/terminal.c
index 7406f50..574ba09 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -52,6 +52,8 @@ static char *option_font;
static int option_font_size;
static char *option_term;
static char *option_shell;
+static char *option_cwd;
+static char *option_command;
static struct wl_list terminal_list;
@@ -3027,7 +3029,13 @@ terminal_run(struct terminal *terminal, const char *path)
if (pid == 0) {
setenv("TERM", option_term, 1);
setenv("COLORTERM", option_term, 1);
- if (execl(path, path, NULL)) {
+ if (option_command) {
+ if (execl(path, path, "-c", option_command, NULL))
+ fprintf(stderr, "command '%s' couldn't executed: %m",
+ option_command);
+ }
+
+ else if (execl(path, path, NULL)) {
printf("exec failed: %m\n");
exit(EXIT_FAILURE);
}
@@ -3055,6 +3063,8 @@ static const struct weston_option terminal_options[] = {
{ WESTON_OPTION_STRING, "font", 0, &option_font },
{ WESTON_OPTION_INTEGER, "font-size", 0, &option_font_size },
{ WESTON_OPTION_STRING, "shell", 0, &option_shell },
+ { WESTON_OPTION_STRING, "cwd", 0, &option_cwd },
+ { WESTON_OPTION_STRING, "command", 0, &option_command },
};
int main(int argc, char *argv[])
@@ -3079,6 +3089,7 @@ int main(int argc, char *argv[])
weston_config_section_get_string(s, "font", &option_font, "mono");
weston_config_section_get_int(s, "font-size", &option_font_size, 14);
weston_config_section_get_string(s, "term", &option_term, "xterm");
+ weston_config_section_get_string(s, "command", &option_command, NULL);
weston_config_destroy(config);
if (parse_options(terminal_options,
@@ -3087,7 +3098,9 @@ int main(int argc, char *argv[])
" --fullscreen or -f\n"
" --font=NAME\n"
" --font-size=SIZE\n"
- " --shell=NAME\n", argv[0]);
+ " --shell=NAME\n"
+ " --cwd=PATH\n"
+ " --command=CMDLINE\n", argv[0]);
return 1;
}
@@ -3099,6 +3112,12 @@ int main(int argc, char *argv[])
wl_list_init(&terminal_list);
terminal = terminal_create(d);
+
+ if (option_cwd) {
+ if(chdir(option_cwd) == -1)
+ fprintf(stderr, "failed to changing directory as %s: %m\n",
+ option_cwd);
+ }
+
if (terminal_run(terminal, option_shell))
exit(EXIT_FAILURE);
--
2.5.3
More information about the wayland-devel
mailing list