Allow a different default shell to be specified

This commit is contained in:
Pierre Pronchery 2013-11-30 02:50:22 +01:00
parent f8b6f2c1f8
commit 7d75aae4f0
3 changed files with 23 additions and 9 deletions

View File

@ -39,7 +39,7 @@
/* private */
/* prototypes */
static int _terminal(void);
static int _terminal(char const * shell);
static int _error(char const * message, int ret);
static int _usage(void);
@ -47,11 +47,11 @@ static int _usage(void);
/* functions */
/* terminal */
static int _terminal(void)
static int _terminal(char const * shell)
{
Terminal * terminal;
if((terminal = terminal_new()) == NULL)
if((terminal = terminal_new(shell)) == NULL)
return error_print(PACKAGE);
gtk_main();
terminal_delete(terminal);
@ -71,7 +71,7 @@ static int _error(char const * message, int ret)
/* usage */
static int _usage(void)
{
fputs(_("Usage: terminal\n"), stderr);
fputs(_("Usage: terminal [shell]\n"), stderr);
return 1;
}
@ -82,6 +82,7 @@ static int _usage(void)
int main(int argc, char * argv[])
{
int o;
char const * shell = NULL;
if(setlocale(LC_ALL, "") == NULL)
_error("setlocale", 1);
@ -94,7 +95,9 @@ int main(int argc, char * argv[])
default:
return _usage();
}
if(optind != argc)
if(argc - optind == 1)
shell = argv[optind];
else if(optind != argc)
return _usage();
return (_terminal() == 0) ? 0 : 2;
return (_terminal(shell) == 0) ? 0 : 2;
}

View File

@ -52,6 +52,8 @@ typedef struct _TerminalTab TerminalTab;
struct _Terminal
{
char * shell;
/* internal */
TerminalTab * tabs;
size_t tabs_cnt;
@ -156,7 +158,7 @@ static DesktopToolbar _terminal_toolbar[] =
/* public */
/* functions */
/* terminal_new */
Terminal * terminal_new(void)
Terminal * terminal_new(char const * shell)
{
Terminal * terminal;
GtkAccelGroup * group;
@ -165,9 +167,16 @@ Terminal * terminal_new(void)
if((terminal = object_new(sizeof(*terminal))) == NULL)
return NULL;
terminal->shell = (shell != NULL) ? strdup(shell) : NULL;
terminal->tabs = NULL;
terminal->tabs_cnt = 0;
terminal->window = NULL;
/* check for errors */
if(shell != NULL && terminal->shell == NULL)
{
terminal_delete(terminal);
return NULL;
}
/* widgets */
group = gtk_accel_group_new();
terminal->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@ -221,6 +230,7 @@ void terminal_delete(Terminal * terminal)
if(terminal->window != NULL)
gtk_widget_destroy(terminal->window);
free(terminal->tabs);
free(terminal->shell);
object_delete(terminal);
}
@ -234,7 +244,7 @@ static int _terminal_open_tab(Terminal * terminal)
TerminalTab * p;
GtkWidget * widget;
char * argv[] = { BINDIR "/xterm", "xterm", "-into", NULL,
"-class", "Terminal", NULL };
"-class", "Terminal", NULL, NULL };
char buf[16];
GSpawnFlags flags = G_SPAWN_FILE_AND_ARGV_ZERO
| G_SPAWN_DO_NOT_REAP_CHILD;
@ -272,6 +282,7 @@ static int _terminal_open_tab(Terminal * terminal)
snprintf(buf, sizeof(buf), "%u", gtk_socket_get_id(
GTK_SOCKET(p->socket)));
argv[3] = buf;
argv[6] = terminal->shell;
if(g_spawn_async(NULL, argv, NULL, flags, NULL, NULL, &p->pid, &error)
== FALSE)
{

View File

@ -27,7 +27,7 @@ typedef struct _Terminal Terminal;
/* functions */
/* essential */
Terminal * terminal_new(void);
Terminal * terminal_new(char const * shell);
void terminal_delete(Terminal * terminal);
#endif /* !TERMINAL_TERMINAL_H */