enum cmd_retval cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct winlink *wl; struct window *w; struct window_pane *wp; struct session *s; struct environ *env; const char *path; char *cause; u_int idx; struct environ_entry *envent; if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL) return (CMD_RETURN_ERROR); w = wl->window; if (!args_has(self->args, 'k') && wp->fd != -1) { if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); cmdq_error(cmdq, "pane still active: %s:%d.%u", s->name, wl->idx, idx); return (CMD_RETURN_ERROR); } env = environ_create(); environ_copy(global_environ, env); environ_copy(s->environ, env); server_fill_environ(s, env); window_pane_reset_mode(wp); screen_reinit(&wp->base); input_init(wp); path = NULL; if (cmdq->client != NULL && cmdq->client->session == NULL) envent = environ_find(cmdq->client->environ, "PATH"); else envent = environ_find(s->environ, "PATH"); if (envent != NULL) path = envent->value; if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, env, s->tio, &cause) != 0) { cmdq_error(cmdq, "respawn pane failed: %s", cause); free(cause); environ_free(env); return (CMD_RETURN_ERROR); } wp->flags |= PANE_REDRAW; server_status_window(w); environ_free(env); return (CMD_RETURN_NORMAL); }
int cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct winlink *wl; struct window *w; struct window_pane *wp; struct session *s; struct environ env; const char *cmd; char *cause; u_int idx; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) return (-1); w = wl->window; if (!args_has(self->args, 'k') && wp->fd != -1) { if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); ctx->error(ctx, "pane still active: %s:%u.%u", s->name, wl->idx, idx); return (-1); } environ_init(&env); environ_copy(&global_environ, &env); environ_copy(&s->environ, &env); server_fill_environ(s, &env); window_pane_reset_mode(wp); screen_reinit(&wp->base); input_init(wp); if (args->argc != 0) cmd = args->argv[0]; else cmd = NULL; if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) { ctx->error(ctx, "respawn pane failed: %s", cause); xfree(cause); environ_free(&env); return (-1); } wp->flags |= PANE_REDRAW; server_status_window(w); environ_free(&env); return (0); }
static enum cmd_retval cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct winlink *wl = item->target.wl; struct window *w = wl->window; struct window_pane *wp = item->target.wp; struct session *s = item->target.s; struct environ *env; const char *path; char *cause; u_int idx; struct environ_entry *envent; if (!args_has(self->args, 'k') && wp->fd != -1) { if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); cmdq_error(item, "pane still active: %s:%d.%u", s->name, wl->idx, idx); return (CMD_RETURN_ERROR); } window_pane_reset_mode(wp); screen_reinit(&wp->base); input_init(wp); path = NULL; if (item->client != NULL && item->client->session == NULL) envent = environ_find(item->client->environ, "PATH"); else envent = environ_find(s->environ, "PATH"); if (envent != NULL) path = envent->value; env = environ_for_session(s, 0); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn pane failed: %s", cause); free(cause); environ_free(env); return (CMD_RETURN_ERROR); } environ_free(env); wp->flags |= PANE_REDRAW; server_status_window(w); return (CMD_RETURN_NORMAL); }
/* Set default format keys for a window pane. */ void format_window_pane(struct format_tree *ft, struct window_pane *wp) { struct grid *gd = wp->base.grid; struct grid_line *gl; unsigned long long size; u_int i; u_int idx; size = 0; for (i = 0; i < gd->hsize; i++) { gl = &gd->linedata[i]; size += gl->cellsize * sizeof *gl->celldata; size += gl->utf8size * sizeof *gl->utf8data; } size += gd->hsize * sizeof *gd->linedata; if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); format_add(ft, "pane_width", "%u", wp->sx); format_add(ft, "pane_height", "%u", wp->sy); format_add(ft, "pane_title", "%s", wp->base.title); format_add(ft, "pane_index", "%u", idx); format_add(ft, "history_size", "%u", gd->hsize); format_add(ft, "history_limit", "%u", gd->hlimit); format_add(ft, "history_bytes", "%llu", size); format_add(ft, "pane_id", "%%%u", wp->id); format_add(ft, "pane_active", "%d", wp == wp->window->active); format_add(ft, "pane_dead", "%d", wp->fd == -1); if (wp->cmd != NULL) format_add(ft, "pane_start_command", "%s", wp->cmd); if (wp->cwd != NULL) format_add(ft, "pane_start_path", "%s", wp->cwd); format_add(ft, "pane_current_path", "%s", get_proc_cwd(wp->pid)); format_add(ft, "pane_pid", "%ld", (long) wp->pid); format_add(ft, "pane_tty", "%s", wp->tty); }
/* Set default format keys for a window pane. */ void format_window_pane(struct format_tree *ft, struct window_pane *wp) { struct grid *gd = wp->base.grid; struct grid_line *gl; unsigned long long size; u_int i, idx; char *cmd, *cwd; size = 0; for (i = 0; i < gd->hsize; i++) { gl = &gd->linedata[i]; size += gl->cellsize * sizeof *gl->celldata; } size += gd->hsize * sizeof *gd->linedata; format_add(ft, "history_size", "%u", gd->hsize); format_add(ft, "history_limit", "%u", gd->hlimit); format_add(ft, "history_bytes", "%llu", size); if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); format_add(ft, "pane_index", "%u", idx); format_add(ft, "pane_width", "%u", wp->sx); format_add(ft, "pane_height", "%u", wp->sy); format_add(ft, "pane_title", "%s", wp->base.title); format_add(ft, "pane_id", "%%%u", wp->id); format_add(ft, "pane_active", "%d", wp == wp->window->active); format_add(ft, "pane_dead", "%d", wp->fd == -1); format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base); format_add(ft, "pane_synchronized", "%d", !!options_get_number(&wp->window->options, "synchronize-panes")); if (wp->tty != NULL) format_add(ft, "pane_tty", "%s", wp->tty); format_add(ft, "pane_pid", "%ld", (long) wp->pid); if (wp->cmd != NULL) format_add(ft, "pane_start_command", "%s", wp->cmd); if ((cwd = osdep_get_cwd(wp->fd)) != NULL) format_add(ft, "pane_current_path", "%s", cwd); if ((cmd = format_get_command(wp)) != NULL) { format_add(ft, "pane_current_command", "%s", cmd); free(cmd); } format_add(ft, "cursor_x", "%d", wp->base.cx); format_add(ft, "cursor_y", "%d", wp->base.cy); format_add(ft, "scroll_region_upper", "%d", wp->base.rupper); format_add(ft, "scroll_region_lower", "%d", wp->base.rlower); format_add(ft, "saved_cursor_x", "%d", wp->ictx.old_cx); format_add(ft, "saved_cursor_y", "%d", wp->ictx.old_cy); format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); format_add(ft, "alternate_saved_x", "%d", wp->saved_cx); format_add(ft, "alternate_saved_y", "%d", wp->saved_cy); format_add(ft, "cursor_flag", "%d", !!(wp->base.mode & MODE_CURSOR)); format_add(ft, "insert_flag", "%d", !!(wp->base.mode & MODE_INSERT)); format_add(ft, "keypad_cursor_flag", "%d", !!(wp->base.mode & MODE_KCURSOR)); format_add(ft, "keypad_flag", "%d", !!(wp->base.mode & MODE_KKEYPAD)); format_add(ft, "wrap_flag", "%d", !!(wp->base.mode & MODE_WRAP)); format_add(ft, "mouse_standard_flag", "%d", !!(wp->base.mode & MODE_MOUSE_STANDARD)); format_add(ft, "mouse_button_flag", "%d", !!(wp->base.mode & MODE_MOUSE_BUTTON)); format_add(ft, "mouse_any_flag", "%d", !!(wp->base.mode & MODE_MOUSE_ANY)); format_add(ft, "mouse_utf8_flag", "%d", !!(wp->base.mode & MODE_MOUSE_UTF8)); format_window_pane_tabs(ft, wp); }
int cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct session *s; struct winlink *wl; struct window *w; struct window_pane *wp, *new_wp = NULL; struct environ env; char *cmd, *cwd, *cause; const char *shell; u_int hlimit, paneidx; int size, percentage; enum layout_type type; struct layout_cell *lc; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) return (-1); w = wl->window; environ_init(&env); environ_copy(&global_environ, &env); environ_copy(&s->environ, &env); server_fill_environ(s, &env); if (args->argc == 0) cmd = options_get_string(&s->options, "default-command"); else cmd = args->argv[0]; cwd = options_get_string(&s->options, "default-path"); if (*cwd == '\0') { if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL) cwd = ctx->cmdclient->cwd; else cwd = s->cwd; } type = LAYOUT_TOPBOTTOM; if (args_has(args, 'h')) type = LAYOUT_LEFTRIGHT; size = -1; if (args_has(args, 's')) { size = args_strtonum(args, 's', 0, INT_MAX, &cause); if (cause != NULL) { ctx->error(ctx, "size %s", cause); xfree(cause); return (-1); } } else if (args_has(args, 'p')) { percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause); if (cause != NULL) { ctx->error(ctx, "percentage %s", cause); xfree(cause); return (-1); } if (type == LAYOUT_TOPBOTTOM) size = (wp->sy * percentage) / 100; else size = (wp->sx * percentage) / 100; } hlimit = options_get_number(&s->options, "history-limit"); shell = options_get_string(&s->options, "default-shell"); if (*shell == '\0' || areshell(shell)) shell = _PATH_BSHELL; if ((lc = layout_split_pane(wp, type, size)) == NULL) { cause = xstrdup("pane too small"); goto error; } new_wp = window_add_pane(w, hlimit); if (window_pane_spawn( new_wp, cmd, shell, cwd, &env, s->tio, &cause) != 0) goto error; layout_assign_pane(lc, new_wp); server_redraw_window(w); if (!args_has(args, 'd')) { window_set_active_pane(w, new_wp); session_select(s, wl->idx); server_redraw_session(s); } else server_status_session(s); environ_free(&env); if (args_has(args, 'P')) { paneidx = window_pane_index(wl->window, new_wp); ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx); } return (0); error: environ_free(&env); if (new_wp != NULL) window_remove_pane(w, new_wp); ctx->error(ctx, "create pane failed: %s", cause); xfree(cause); return (-1); }