add an -e switch

This commit is contained in:
Daniel Micay 2012-06-16 00:31:50 -04:00
parent dc9abb2244
commit b938d4fbce
1 changed files with 12 additions and 3 deletions

View File

@ -445,12 +445,14 @@ int main(int argc, char **argv) {
const char *term = "vte-256color"; const char *term = "vte-256color";
gboolean dynamic_title = FALSE, urgent_on_bell = FALSE, clickable_url = FALSE; gboolean dynamic_title = FALSE, urgent_on_bell = FALSE, clickable_url = FALSE;
GOptionContext *context = g_option_context_new("[COMMAND]"); GOptionContext *context = g_option_context_new(NULL);
gchar *role = NULL; gchar *role = NULL;
char *geometry = NULL; char *geometry = NULL;
char *execute = NULL;
const GOptionEntry entries[] = { const GOptionEntry entries[] = {
{"role", 'r', 0, G_OPTION_ARG_STRING, &role, "The role to use", "ROLE"}, {"role", 'r', 0, G_OPTION_ARG_STRING, &role, "The role to use", "ROLE"},
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry, "Window geometry", "GEOMETRY"}, {"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry, "Window geometry", "GEOMETRY"},
{"exec", 'e', 0, G_OPTION_ARG_STRING, &execute, "Command to execute", "COMMAND"},
{NULL} {NULL}
}; };
g_option_context_add_main_entries(context, entries, NULL); g_option_context_add_main_entries(context, entries, NULL);
@ -481,8 +483,15 @@ int main(int argc, char **argv) {
char fallback[] = "/bin/sh"; char fallback[] = "/bin/sh";
char *default_argv[2] = {fallback, NULL}; char *default_argv[2] = {fallback, NULL};
if (argc > 1) { if (execute) {
command_argv = &argv[1]; gint argcp;
gchar **argvp;
g_shell_parse_argv(execute, &argcp, &argvp, &error);
if (error) {
g_printerr("Failed to parse command: %s\n", error->message);
return 1;
}
command_argv = argvp;
} else { } else {
char *shell = vte_get_user_shell(); char *shell = vte_get_user_shell();
if (shell) default_argv[0] = shell; if (shell) default_argv[0] = shell;