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 */ /* private */
/* prototypes */ /* prototypes */
static int _terminal(void); static int _terminal(char const * shell);
static int _error(char const * message, int ret); static int _error(char const * message, int ret);
static int _usage(void); static int _usage(void);
@ -47,11 +47,11 @@ static int _usage(void);
/* functions */ /* functions */
/* terminal */ /* terminal */
static int _terminal(void) static int _terminal(char const * shell)
{ {
Terminal * terminal; Terminal * terminal;
if((terminal = terminal_new()) == NULL) if((terminal = terminal_new(shell)) == NULL)
return error_print(PACKAGE); return error_print(PACKAGE);
gtk_main(); gtk_main();
terminal_delete(terminal); terminal_delete(terminal);
@ -71,7 +71,7 @@ static int _error(char const * message, int ret)
/* usage */ /* usage */
static int _usage(void) static int _usage(void)
{ {
fputs(_("Usage: terminal\n"), stderr); fputs(_("Usage: terminal [shell]\n"), stderr);
return 1; return 1;
} }
@ -82,6 +82,7 @@ static int _usage(void)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int o; int o;
char const * shell = NULL;
if(setlocale(LC_ALL, "") == NULL) if(setlocale(LC_ALL, "") == NULL)
_error("setlocale", 1); _error("setlocale", 1);
@ -94,7 +95,9 @@ int main(int argc, char * argv[])
default: default:
return _usage(); return _usage();
} }
if(optind != argc) if(argc - optind == 1)
shell = argv[optind];
else if(optind != argc)
return _usage(); 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 struct _Terminal
{ {
char * shell;
/* internal */ /* internal */
TerminalTab * tabs; TerminalTab * tabs;
size_t tabs_cnt; size_t tabs_cnt;
@ -156,7 +158,7 @@ static DesktopToolbar _terminal_toolbar[] =
/* public */ /* public */
/* functions */ /* functions */
/* terminal_new */ /* terminal_new */
Terminal * terminal_new(void) Terminal * terminal_new(char const * shell)
{ {
Terminal * terminal; Terminal * terminal;
GtkAccelGroup * group; GtkAccelGroup * group;
@ -165,9 +167,16 @@ Terminal * terminal_new(void)
if((terminal = object_new(sizeof(*terminal))) == NULL) if((terminal = object_new(sizeof(*terminal))) == NULL)
return NULL; return NULL;
terminal->shell = (shell != NULL) ? strdup(shell) : NULL;
terminal->tabs = NULL; terminal->tabs = NULL;
terminal->tabs_cnt = 0; terminal->tabs_cnt = 0;
terminal->window = NULL; terminal->window = NULL;
/* check for errors */
if(shell != NULL && terminal->shell == NULL)
{
terminal_delete(terminal);
return NULL;
}
/* widgets */ /* widgets */
group = gtk_accel_group_new(); group = gtk_accel_group_new();
terminal->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); terminal->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@ -221,6 +230,7 @@ void terminal_delete(Terminal * terminal)
if(terminal->window != NULL) if(terminal->window != NULL)
gtk_widget_destroy(terminal->window); gtk_widget_destroy(terminal->window);
free(terminal->tabs); free(terminal->tabs);
free(terminal->shell);
object_delete(terminal); object_delete(terminal);
} }
@ -234,7 +244,7 @@ static int _terminal_open_tab(Terminal * terminal)
TerminalTab * p; TerminalTab * p;
GtkWidget * widget; GtkWidget * widget;
char * argv[] = { BINDIR "/xterm", "xterm", "-into", NULL, char * argv[] = { BINDIR "/xterm", "xterm", "-into", NULL,
"-class", "Terminal", NULL }; "-class", "Terminal", NULL, NULL };
char buf[16]; char buf[16];
GSpawnFlags flags = G_SPAWN_FILE_AND_ARGV_ZERO GSpawnFlags flags = G_SPAWN_FILE_AND_ARGV_ZERO
| G_SPAWN_DO_NOT_REAP_CHILD; | 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( snprintf(buf, sizeof(buf), "%u", gtk_socket_get_id(
GTK_SOCKET(p->socket))); GTK_SOCKET(p->socket)));
argv[3] = buf; argv[3] = buf;
argv[6] = terminal->shell;
if(g_spawn_async(NULL, argv, NULL, flags, NULL, NULL, &p->pid, &error) if(g_spawn_async(NULL, argv, NULL, flags, NULL, NULL, &p->pid, &error)
== FALSE) == FALSE)
{ {

View File

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