Exemplo n.º 1
0
static enum cmd_retval
cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args			*args = self->args;
	struct cmd_run_shell_data	*cdata;
	struct client			*c = cmd_find_client(item, NULL, 1);
	struct session			*s = item->target.s;
	struct winlink			*wl = item->target.wl;
	struct window_pane		*wp = item->target.wp;

	cdata = xcalloc(1, sizeof *cdata);
	cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);

	if (args_has(args, 't') && wp != NULL)
		cdata->wp_id = wp->id;
	else
		cdata->wp_id = -1;

	if (!args_has(args, 'b'))
		cdata->item = item;

	job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL,
	    cmd_run_shell_callback, cmd_run_shell_free, cdata, 0);

	if (args_has(args, 'b'))
		return (CMD_RETURN_NORMAL);
	return (CMD_RETURN_WAIT);
}
Exemplo n.º 2
0
int
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args		*args = self->args;
	struct client		*c;
	struct session		*s;
	struct winlink		*wl;
	struct window_pane	*wp;
	const char		*template;
	char			*msg;
	struct format_tree	*ft;
	char			 out[BUFSIZ];
	time_t			 t;
	size_t			 len;

	if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
		return (-1);

	if (args_has(args, 't')) {
		wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
		if (wl == NULL)
			return (-1);
	} else {
		wl = cmd_find_pane(ctx, NULL, &s, &wp);
		if (wl == NULL)
			return (-1);
	}

	if (args_has(args, 'F') && args->argc != 0) {
		ctx->error(ctx, "only one of -F or argument must be given");
		return (-1);
	}
Exemplo n.º 3
0
enum cmd_retval
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args			*args = self->args;
	struct cmd_confirm_before_data	*cdata;
	struct client			*c;
	char				*cmd, *copy, *new_prompt, *ptr;
	const char			*prompt;

	if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
		return (CMD_RETURN_ERROR);

	if ((prompt = args_get(args, 'p')) != NULL)
		xasprintf(&new_prompt, "%s ", prompt);
	else {
		ptr = copy = xstrdup(args->argv[0]);
		cmd = strsep(&ptr, " \t");
		xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
		free(copy);
	}

	cdata = xmalloc(sizeof *cdata);
	cdata->cmd = xstrdup(args->argv[0]);

	cdata->client = c;
	cdata->client->references++;

	status_prompt_set(c, new_prompt, NULL,
	    cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
	    PROMPT_SINGLE);

	free(new_prompt);
	return (CMD_RETURN_NORMAL);
}
Exemplo n.º 4
0
int
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;
	struct session 	*s;
	enum msgtype     msgtype;
	u_int 		 i;

	if (args_has(args, 'P'))
		msgtype = MSG_DETACHKILL;
	else
		msgtype = MSG_DETACH;

	if (args_has(args, 's')) {
		s = cmd_find_session(ctx, args_get(args, 's'), 0);
		if (s == NULL)
			return (-1);

		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
			c = ARRAY_ITEM(&clients, i);
			if (c != NULL && c->session == s)
				server_write_client(c, msgtype, NULL, 0);
		}
	} else {
		c = cmd_find_client(ctx, args_get(args, 't'));
		if (c == NULL)
			return (-1);

		server_write_client(c, msgtype, NULL, 0);
	}

	return (0);
}
Exemplo n.º 5
0
int
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_switch_client_data	*data = self->data;
	struct client			*c;
	struct session			*s;

	if (data == NULL)
		return (0);

	if ((c = cmd_find_client(ctx, data->name)) == NULL)
		return (-1);

	if (data->flag_next) {
		if ((s = session_next_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find next session");
			return (-1);
		}
	} else if (data->flag_previous) {
		if ((s = session_previous_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find previous session");
			return (-1);
		}
	} else
		s = cmd_find_session(ctx, data->target);

	if (s == NULL)
		return (-1);
	c->session = s;

	recalculate_sizes();
	server_redraw_client(c);

	return (0);
}
Exemplo n.º 6
0
int
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args		*args = self->args;
	struct client		*c;
	struct session		*s;
	struct winlink		*wl;
	struct window_pane	*wp;
	const char		*template;
	char			*msg;

	if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
		return (-1);

	if (args_has(args, 't') != 0) {
		wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
		if (wl == NULL)
			return (-1);
	} else {
		s = NULL;
		wl = NULL;
		wp = NULL;
	}

	if (args->argc == 0)
Exemplo n.º 7
0
int
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
    struct args		*args = self->args;
    struct winlink		*wl;
    struct session		*s;
    struct window_pane	*wp;
    struct window		*w;
    char			*name;
    char			*cause;
    int			 base_idx;
    struct client		*c;

    if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
        return (-1);

    if (window_count_panes(wl->window) == 1) {
        ctx->error(ctx, "can't break with only one pane");
        return (-1);
    }

    w = wl->window;
    TAILQ_REMOVE(&w->panes, wp, entry);
    if (wp == w->active) {
        w->active = w->last;
        w->last = NULL;
        if (w->active == NULL) {
            w->active = TAILQ_PREV(wp, window_panes, entry);
            if (w->active == NULL)
                w->active = TAILQ_NEXT(wp, entry);
        }
    } else if (wp == w->last)
        w->last = NULL;
    layout_close_pane(wp);

    w = wp->window = window_create1(s->sx, s->sy);
    TAILQ_INSERT_HEAD(&w->panes, wp, entry);
    w->active = wp;
    name = default_window_name(w);
    window_set_name(w, name);
    xfree(name);
    layout_init(w);

    base_idx = options_get_number(&s->options, "base-index");
    wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
    if (!args_has(self->args, 'd'))
        session_select(s, wl->idx);

    server_redraw_session(s);
    server_status_session_group(s);

    /* Output the window ID for control clients. */
    c = cmd_find_client(ctx, NULL);
    if (c->flags & CLIENT_CONTROL) {
        ctx->print(ctx, "%d", w->id);
    }

    return (0);
}
Exemplo n.º 8
0
static enum cmd_retval
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args		*args = self->args;
	struct cmd_find_state	*current = &item->shared->current;
	struct session		*s = item->target.s;
	struct winlink		*wl = item->target.wl;
	struct client		*c = cmd_find_client(item, NULL, 1);
	int			 idx = item->target.idx;
	const char		*cmd, *path, *template, *tmp;
Exemplo n.º 9
0
int
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;
	struct session	*s;

	if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
		return (-1);

	if (args_has(args, 'r')) {
		if (c->flags & CLIENT_READONLY) {
			c->flags &= ~CLIENT_READONLY;
			ctx->info(ctx, "made client writable");
		} else {
			c->flags |= CLIENT_READONLY;
			ctx->info(ctx, "made client read-only");
		}
	}

	s = NULL;
	if (args_has(args, 'n')) {
		if ((s = session_next_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find next session");
			return (-1);
		}
	} else if (args_has(args, 'p')) {
		if ((s = session_previous_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find previous session");
			return (-1);
		}
	} else if (args_has(args, 'l')) {
		if (c->last_session != NULL && session_alive(c->last_session))
			s = c->last_session;
		if (s == NULL) {
			ctx->error(ctx, "can't find last session");
			return (-1);
		}
	} else
		s = cmd_find_session(ctx, args_get(args, 't'), 0);
	if (s == NULL)
		return (-1);

	if (c->session != NULL)
		c->last_session = c->session;
	c->session = s;
	session_update_activity(s);

	recalculate_sizes();
	server_check_unattached();
	server_redraw_client(c);
	s->curw->flags &= ~WINLINK_ALERTFLAGS;

	return (0);
}
Exemplo n.º 10
0
int
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data	*data = self->data;
	struct client		*c;
	const char		*template;
	char			*msg;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	if (data->arg == NULL)
Exemplo n.º 11
0
int
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data	*data = self->data;
	struct client		*c;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	server_write_client(c, MSG_DETACH, NULL, 0);

	return (0);
}
Exemplo n.º 12
0
int
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
		return (-1);

	server_redraw_client(c);

	return (0);
}
Exemplo n.º 13
0
int
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
		return (-1);

	server_write_client(c, MSG_DETACH, NULL, 0);

	return (0);
}
Exemplo n.º 14
0
int
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data	*data = self->data;
	struct client		*c;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	server_set_identify(c);

	return (0);
}
Exemplo n.º 15
0
int
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
		return (-1);

	server_set_identify(c);

	return (0);
}
Exemplo n.º 16
0
enum cmd_retval
cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
		return (CMD_RETURN_ERROR);

	server_set_identify(c);

	return (CMD_RETURN_NORMAL);
}
Exemplo n.º 17
0
int
cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data	*data = self->data;
	struct client		*c;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	server_lock_client(c);
	recalculate_sizes();

	return (0);
}
Exemplo n.º 18
0
int
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data	*data = self->data;
	struct client		*c;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	tty_stop_tty(&c->tty);
	c->flags |= CLIENT_SUSPENDED;
	server_write_client(c, MSG_SUSPEND, NULL, 0);

	return (0);
}
Exemplo n.º 19
0
enum cmd_retval
cmd_suspend_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
		return (CMD_RETURN_ERROR);

	tty_stop_tty(&c->tty);
	c->flags |= CLIENT_SUSPENDED;
	server_write_client(c, MSG_SUSPEND, NULL, 0);

	return (CMD_RETURN_NORMAL);
}
Exemplo n.º 20
0
int
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;

	if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
		return (-1);

	tty_stop_tty(&c->tty);
	c->flags |= CLIENT_SUSPENDED;
	server_write_client(c, MSG_SUSPEND, NULL, 0);

	return (0);
}
Exemplo n.º 21
0
int
cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
{
    struct cmd_target_data	*data = self->data;
    struct client		*c;

    if ((c = cmd_find_client(ctx, data->target)) == NULL)
        return (-1);

    if (c->prompt_string != NULL)
        return (0);

    status_prompt_set(c, "index ", cmd_select_prompt_callback, NULL, c, 0);

    return (0);
}
Exemplo n.º 22
0
int
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_switch_client_data	*data = self->data;
	struct client			*c;
	struct session			*s;

	if (data == NULL)
		return (0);

	if ((c = cmd_find_client(ctx, data->name)) == NULL)
		return (-1);

	s = NULL;
	if (data->flag_next) {
		if ((s = session_next_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find next session");
			return (-1);
		}
	} else if (data->flag_previous) {
		if ((s = session_previous_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find previous session");
			return (-1);
		}
	} else if (data->flag_last) {
		if (c->last_session != NULL && session_alive(c->last_session))
			s = c->last_session;
		if (s == NULL) {
			ctx->error(ctx, "can't find last session");
			return (-1);
		}
	} else
		s = cmd_find_session(ctx, data->target);
	if (s == NULL)
		return (-1);

	if (c->session != NULL)
		c->last_session = c->session;
	c->session = s;
	session_update_activity(s);

	recalculate_sizes();
	server_check_unattached();
	server_redraw_client(c);

	return (0);
}
Exemplo n.º 23
0
enum cmd_retval
cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args			*args = self->args;
	struct cmd_run_shell_data	*cdata;
	char				*shellcmd;
	struct client			*c;
	struct session			*s = NULL;
	struct winlink			*wl = NULL;
	struct window_pane		*wp = NULL;
	struct format_tree		*ft;

	if (args_has(args, 't'))
		wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
	else {
		c = cmd_find_client(cmdq, NULL, 1);
		if (c != NULL && c->session != NULL) {
			s = c->session;
			wl = s->curw;
			wp = wl->window->active;
		}
	}

	ft = format_create();
	if (s != NULL)
		format_session(ft, s);
	if (s != NULL && wl != NULL)
		format_winlink(ft, s, wl);
	if (wp != NULL)
		format_window_pane(ft, wp);
	shellcmd = format_expand(ft, args->argv[0]);
	format_free(ft);

	cdata = xmalloc(sizeof *cdata);
	cdata->cmd = shellcmd;
	cdata->bflag = args_has(args, 'b');
	cdata->wp_id = wp != NULL ? (int) wp->id : -1;

	cdata->cmdq = cmdq;
	cmdq->references++;

	job_run(shellcmd, s, cmd_run_shell_callback, cmd_run_shell_free, cdata);

	if (cdata->bflag)
		return (CMD_RETURN_NORMAL);
	return (CMD_RETURN_WAIT);
}
Exemplo n.º 24
0
static enum cmd_retval
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args		*args = self->args;
	struct client		*c;
	struct session		*s = item->target.s;
	struct winlink		*wl = item->target.wl;
	struct window_pane	*wp = item->target.wp;
	const char		*template;
	char			*msg;
	struct format_tree	*ft;

	if (args_has(args, 'F') && args->argc != 0) {
		cmdq_error(item, "only one of -F or argument must be given");
		return (CMD_RETURN_ERROR);
	}
	c = cmd_find_client(item, args_get(args, 'c'), 1);
Exemplo n.º 25
0
int
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_target_data		*data = self->data;
	struct cmd_command_prompt_data	*cdata;
	struct client			*c;
	char				*hdr, *ptr;

	if ((c = cmd_find_client(ctx, data->target)) == NULL)
		return (-1);

	if (c->prompt_string != NULL)
		return (0);

	cdata = xmalloc(sizeof *cdata);
	cdata->c = c;
	if (data->arg != NULL) {
		cdata->template = xstrdup(data->arg);
int
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c;
	struct session	*s;

	if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
		return (-1);

	s = NULL;
	if (args_has(args, 'n')) {
		if ((s = session_next_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find next session");
			return (-1);
		}
	} else if (args_has(args, 'p')) {
		if ((s = session_previous_session(c->session)) == NULL) {
			ctx->error(ctx, "can't find previous session");
			return (-1);
		}
	} else if (args_has(args, 'l')) {
		if (c->last_session != NULL && session_alive(c->last_session))
			s = c->last_session;
		if (s == NULL) {
			ctx->error(ctx, "can't find last session");
			return (-1);
		}
	} else
		s = cmd_find_session(ctx, args_get(args, 't'), 0);
	if (s == NULL)
		return (-1);

	if (c->session != NULL)
		c->last_session = c->session;
	c->session = s;
	session_update_activity(s);

	recalculate_sizes();
	server_check_unattached();
	server_redraw_client(c);

	return (0);
}
Exemplo n.º 27
0
static enum cmd_retval
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
{
	struct args	*args = self->args;
	struct client	*c;
	const char	*size;
	u_int		 w, h;

	if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
		return (CMD_RETURN_ERROR);

	if (args_has(args, 'C')) {
		if ((size = args_get(args, 'C')) == NULL) {
			cmdq_error(item, "missing size");
			return (CMD_RETURN_ERROR);
		}
		if (sscanf(size, "%u,%u", &w, &h) != 2) {
			cmdq_error(item, "bad size argument");
			return (CMD_RETURN_ERROR);
		}
		if (w < PANE_MINIMUM || w > 5000 ||
		    h < PANE_MINIMUM || h > 5000) {
			cmdq_error(item, "size too small or too big");
			return (CMD_RETURN_ERROR);
		}
		if (!(c->flags & CLIENT_CONTROL)) {
			cmdq_error(item, "not a control client");
			return (CMD_RETURN_ERROR);
		}
		tty_set_size(&c->tty, w, h);
		c->flags |= CLIENT_SIZECHANGED;
		recalculate_sizes();
	} else if (args_has(args, 'S')) {
		c->flags |= CLIENT_STATUSFORCE;
		server_status_client(c);
	} else {
		c->flags |= CLIENT_STATUSFORCE;
		server_redraw_client(c);
	}

	return (CMD_RETURN_NORMAL);
}
Exemplo n.º 28
0
enum cmd_retval
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args	*args = self->args;
	struct client	*c, *c2;
	struct session 	*s;
	enum msgtype     msgtype;
	u_int 		 i;

	if (args_has(args, 'P'))
		msgtype = MSG_DETACHKILL;
	else
		msgtype = MSG_DETACH;

	if (args_has(args, 's')) {
		s = cmd_find_session(cmdq, args_get(args, 's'), 0);
		if (s == NULL)
			return (CMD_RETURN_ERROR);

		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
			c = ARRAY_ITEM(&clients, i);
			if (c != NULL && c->session == s)
				server_write_client(c, msgtype, NULL, 0);
		}
	} else {
		c = cmd_find_client(cmdq, args_get(args, 't'), 0);
		if (c == NULL)
			return (CMD_RETURN_ERROR);

		if (args_has(args, 'a')) {
			for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
				c2 = ARRAY_ITEM(&clients, i);
				if (c2 == NULL || c == c2)
					continue;
				server_write_client(c2, msgtype, NULL, 0);
			}
		} else
			server_write_client(c, msgtype, NULL, 0);
	}

	return (CMD_RETURN_STOP);
}
Exemplo n.º 29
0
enum cmd_retval
cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args		*args = self->args;
	struct client		*c;
	struct session		*s;
	struct winlink		*wl;
	struct window_pane	*wp;
	const char		*template;
	char			*msg;
	struct format_tree	*ft;
	char			 out[BUFSIZ];
	time_t			 t;
	size_t			 len;

	if (args_has(args, 't')) {
		wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
		if (wl == NULL)
			return (CMD_RETURN_ERROR);
	} else {
		wl = cmd_find_pane(cmdq, NULL, &s, &wp);
		if (wl == NULL)
			return (CMD_RETURN_ERROR);
	}

	if (args_has(args, 'F') && args->argc != 0) {
		cmdq_error(cmdq, "only one of -F or argument must be given");
		return (CMD_RETURN_ERROR);
	}

	if (args_has(args, 'c')) {
	    c = cmd_find_client(cmdq, args_get(args, 'c'), 0);
	    if (c == NULL)
		return (CMD_RETURN_ERROR);
	} else {
		c = cmd_current_client(cmdq);
		if (c == NULL && !args_has(self->args, 'p')) {
			cmdq_error(cmdq, "no client available");
			return (CMD_RETURN_ERROR);
		}
	}
Exemplo n.º 30
0
int
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
{
    struct args		*args = self->args;
    struct client		*c;
    struct message_entry	*msg;
    char			*tim;
    u_int			 i;

    if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
        return (-1);

    for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
        msg = &ARRAY_ITEM(&c->message_log, i);

        tim = ctime(&msg->msg_time);
        *strchr(tim, '\n') = '\0';

        ctx->print(ctx, "%s %s", tim, msg->msg);
    }

    return (0);
}