diff options
-rw-r--r-- | names.c | 15 | ||||
-rw-r--r-- | tmux.1 | 8 | ||||
-rw-r--r-- | tmux.c | 13 | ||||
-rw-r--r-- | tmux.h | 1 | ||||
-rw-r--r-- | window.c | 34 |
5 files changed, 53 insertions, 18 deletions
@@ -59,7 +59,16 @@ set_window_names(void) if (name == NULL) wname = default_window_name(w); else { - wname = parse_window_name(name); + /* + * If tmux is using the default command, it will be a + * login shell and argv[0] may have a - prefix. Remove + * this if it is present. Ick. + */ + if (w->active->cmd != NULL && *w->active->cmd == '\0' && + name != NULL && name[0] == '-' && name[1] != '\0') + wname = parse_window_name(name + 1); + else + wname = parse_window_name(name); xfree(name); } @@ -78,7 +87,9 @@ default_window_name(struct window *w) { if (w->active->screen != &w->active->base) return (xstrdup("[tmux]")); - return (parse_window_name(w->active->cmd)); + if (w->active->cmd != NULL && *w->active->cmd != '\0') + return (parse_window_name(w->active->cmd)); + return (parse_window_name(window_default_command())); } char * @@ -1070,8 +1070,12 @@ maintain this maximum length. Set the command used for new windows (if not specified when the window is created) to .Ar command . -The default is -.Dq exec $SHELL -l . +The default is an empty string, which instructs +.Nm +to create a login shell using the +.Ev SHELL +environment variable or, if it is unset, the user's shell returned by +.Xr getpwuid 3 . .It Ic default-path Ar path Set the default working directory for processes created from keys, or interactively from the prompt. @@ -209,7 +209,6 @@ main(int argc, char **argv) struct cmd *cmd; struct pollfd pfd; struct hdr hdr; - const char *shell; struct passwd *pw; char *s, *path, *label, *cause, *home, *pass = NULL; char cwd[MAXPATHLEN]; @@ -270,6 +269,7 @@ main(int argc, char **argv) options_init(&global_s_options, NULL); options_set_number(&global_s_options, "bell-action", BELL_ANY); options_set_number(&global_s_options, "buffer-limit", 9); + options_set_string(&global_s_options, "default-command", "%s", ""); options_set_number(&global_s_options, "display-time", 750); options_set_number(&global_s_options, "history-limit", 2000); options_set_number(&global_s_options, "lock-after-time", 0); @@ -358,17 +358,6 @@ main(int argc, char **argv) } xfree(label); - shell = getenv("SHELL"); - if (shell == NULL || *shell == '\0') { - pw = getpwuid(getuid()); - if (pw != NULL) - shell = pw->pw_shell; - if (shell == NULL || *shell == '\0') - shell = _PATH_BSHELL; - } - options_set_string( - &global_s_options, "default-command", "exec %s -l", shell); - if (getcwd(cwd, sizeof cwd) == NULL) { pw = getpwuid(getuid()); if (pw->pw_dir != NULL && *pw->pw_dir != '\0') @@ -1408,6 +1408,7 @@ int screen_check_selection(struct screen *, u_int, u_int); /* window.c */ extern struct windows windows; +const char *window_default_command(void); int window_cmp(struct window *, struct window *); int winlink_cmp(struct winlink *, struct winlink *); RB_PROTOTYPE(windows, window, entry, window_cmp); @@ -23,6 +23,7 @@ #include <fcntl.h> #include <fnmatch.h> #include <paths.h> +#include <pwd.h> #include <signal.h> #include <stdint.h> #include <stdlib.h> @@ -57,6 +58,23 @@ struct windows windows; RB_GENERATE(winlinks, winlink, entry, winlink_cmp); +const char * +window_default_command(void) +{ + const char *shell; + struct passwd *pw; + + shell = getenv("SHELL"); + if (shell != NULL && *shell != '\0') + return (shell); + + pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_shell != NULL && *pw->pw_shell != '\0') + return (pw->pw_shell); + + return (_PATH_BSHELL); +} + int winlink_cmp(struct winlink *wl1, struct winlink *wl2) { @@ -424,7 +442,8 @@ window_pane_spawn(struct window_pane *wp, { struct winsize ws; int mode; - const char **envq; + const char **envq, *ptr; + char *argv0; struct timeval tv; if (wp->fd != -1) @@ -465,7 +484,18 @@ window_pane_spawn(struct window_pane *wp, sigreset(); log_close(); - execl(_PATH_BSHELL, "sh", "-c", wp->cmd, (char *) NULL); + if (*wp->cmd != '\0') { + execl(_PATH_BSHELL, "sh", "-c", wp->cmd, (char *) NULL); + fatal("execl failed"); + } + + /* No command; fork a login shell. */ + cmd = window_default_command(); + if ((ptr = strrchr(cmd, '/')) != NULL && *(ptr + 1) != '\0') + xasprintf(&argv0, "-%s", ptr + 1); + else + xasprintf(&argv0, "-%s", cmd); + execl(cmd, argv0, (char *) NULL); fatal("execl failed"); } |