2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2013-10-10 12:26:34 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2009-09-01 13:09:49 +00:00
|
|
|
#include <paths.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <stdlib.h>
|
2013-10-10 12:26:34 +00:00
|
|
|
#include <string.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Split a window (add a new pane).
|
|
|
|
*/
|
|
|
|
|
2014-10-20 23:35:28 +00:00
|
|
|
#define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
|
|
|
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_split_window_exec(struct cmd *,
|
|
|
|
struct cmdq_item *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
const struct cmd_entry cmd_split_window_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "split-window",
|
|
|
|
.alias = "splitw",
|
|
|
|
|
2016-09-04 17:37:06 +00:00
|
|
|
.args = { "bc:dfF:l:hp:Pt:v", 0, -1 },
|
|
|
|
.usage = "[-bdfhvP] [-c start-directory] [-F format] "
|
2015-12-13 21:53:57 +00:00
|
|
|
"[-p percentage|-l size] " CMD_TARGET_PANE_USAGE " [command]",
|
|
|
|
|
2017-04-22 10:22:39 +00:00
|
|
|
.target = { 't', CMD_FIND_PANE, 0 },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
|
|
|
.flags = 0,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_split_window_exec
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-04-22 08:56:24 +00:00
|
|
|
struct cmd_find_state *current = &item->shared->current;
|
2011-01-04 00:42:46 +00:00
|
|
|
struct args *args = self->args;
|
2017-04-22 10:22:39 +00:00
|
|
|
struct client *c = cmd_find_client(item, NULL, 1);
|
|
|
|
struct session *s = item->target.s;
|
|
|
|
struct winlink *wl = item->target.wl;
|
2015-12-13 14:32:38 +00:00
|
|
|
struct window *w = wl->window;
|
2017-04-22 10:22:39 +00:00
|
|
|
struct window_pane *wp = item->target.wp, *new_wp = NULL;
|
2015-10-28 09:51:55 +00:00
|
|
|
struct environ *env;
|
2018-03-01 12:53:08 +00:00
|
|
|
const char *cmd, *path, *shell, *template, *tmp;
|
|
|
|
char **argv, *cause, *new_cause, *cp, *cwd;
|
2012-03-04 20:50:53 +00:00
|
|
|
u_int hlimit;
|
2018-03-16 15:15:39 +00:00
|
|
|
int argc, size, percentage, before;
|
2011-01-04 00:42:46 +00:00
|
|
|
enum layout_type type;
|
|
|
|
struct layout_cell *lc;
|
2014-04-17 13:02:59 +00:00
|
|
|
struct environ_entry *envent;
|
2016-10-13 22:48:51 +00:00
|
|
|
struct cmd_find_state fs;
|
2011-01-04 00:42:46 +00:00
|
|
|
|
2013-03-24 09:57:59 +00:00
|
|
|
server_unzoom_window(w);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2014-05-13 08:08:32 +00:00
|
|
|
if (args->argc == 0) {
|
2015-10-27 15:58:42 +00:00
|
|
|
cmd = options_get_string(s->options, "default-command");
|
2014-05-13 08:08:32 +00:00
|
|
|
if (cmd != NULL && *cmd != '\0') {
|
|
|
|
argc = 1;
|
2014-09-01 21:50:18 +00:00
|
|
|
argv = (char **)&cmd;
|
2014-05-13 08:08:32 +00:00
|
|
|
} else {
|
|
|
|
argc = 0;
|
|
|
|
argv = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
argc = args->argc;
|
|
|
|
argv = args->argv;
|
|
|
|
}
|
2013-10-10 12:26:34 +00:00
|
|
|
|
2018-03-01 12:53:08 +00:00
|
|
|
if ((tmp = args_get(args, 'c')) != NULL)
|
|
|
|
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
2013-10-10 12:26:34 +00:00
|
|
|
else
|
2018-05-24 09:42:49 +00:00
|
|
|
cwd = xstrdup(server_client_get_cwd(item->client, s));
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-11-20 19:12:39 +00:00
|
|
|
type = LAYOUT_TOPBOTTOM;
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(args, 'h'))
|
2009-11-20 19:12:39 +00:00
|
|
|
type = LAYOUT_LEFTRIGHT;
|
2018-03-16 15:15:39 +00:00
|
|
|
before = args_has(args, 'b');
|
2009-11-20 19:12:39 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
size = -1;
|
2011-02-10 12:12:14 +00:00
|
|
|
if (args_has(args, 'l')) {
|
|
|
|
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
2011-01-04 00:42:46 +00:00
|
|
|
if (cause != NULL) {
|
2011-08-30 09:18:52 +00:00
|
|
|
xasprintf(&new_cause, "size %s", cause);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(cause);
|
2011-08-30 09:18:52 +00:00
|
|
|
cause = new_cause;
|
|
|
|
goto error;
|
2011-01-04 00:42:46 +00:00
|
|
|
}
|
|
|
|
} else if (args_has(args, 'p')) {
|
|
|
|
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
|
|
|
|
if (cause != NULL) {
|
2011-08-30 09:18:52 +00:00
|
|
|
xasprintf(&new_cause, "percentage %s", cause);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(cause);
|
2011-08-30 09:18:52 +00:00
|
|
|
cause = new_cause;
|
|
|
|
goto error;
|
2011-01-04 00:42:46 +00:00
|
|
|
}
|
2009-11-20 19:12:39 +00:00
|
|
|
if (type == LAYOUT_TOPBOTTOM)
|
2011-01-04 00:42:46 +00:00
|
|
|
size = (wp->sy * percentage) / 100;
|
2009-11-20 19:12:39 +00:00
|
|
|
else
|
2011-01-04 00:42:46 +00:00
|
|
|
size = (wp->sx * percentage) / 100;
|
2009-11-20 19:12:39 +00:00
|
|
|
}
|
2015-10-27 15:58:42 +00:00
|
|
|
hlimit = options_get_number(s->options, "history-limit");
|
2009-07-19 13:21:40 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
shell = options_get_string(s->options, "default-shell");
|
2009-09-01 13:09:49 +00:00
|
|
|
if (*shell == '\0' || areshell(shell))
|
|
|
|
shell = _PATH_BSHELL;
|
|
|
|
|
2018-03-16 15:15:39 +00:00
|
|
|
lc = layout_split_pane(wp, type, size, before, args_has(args, 'f'));
|
2014-11-12 22:57:06 +00:00
|
|
|
if (lc == NULL) {
|
2009-07-19 13:21:40 +00:00
|
|
|
cause = xstrdup("pane too small");
|
|
|
|
goto error;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2018-03-16 15:15:39 +00:00
|
|
|
new_wp = window_add_pane(w, wp, before, args_has(args, 'f'), hlimit);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
layout_make_leaf(lc, new_wp);
|
2014-04-17 13:02:59 +00:00
|
|
|
|
|
|
|
path = NULL;
|
2016-10-16 19:04:05 +00:00
|
|
|
if (item->client != NULL && item->client->session == NULL)
|
|
|
|
envent = environ_find(item->client->environ, "PATH");
|
2014-04-17 13:02:59 +00:00
|
|
|
else
|
2015-10-28 09:51:55 +00:00
|
|
|
envent = environ_find(s->environ, "PATH");
|
2014-04-17 13:02:59 +00:00
|
|
|
if (envent != NULL)
|
|
|
|
path = envent->value;
|
|
|
|
|
2017-04-25 15:35:10 +00:00
|
|
|
env = environ_for_session(s, 0);
|
2015-10-28 09:51:55 +00:00
|
|
|
if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env,
|
2017-03-09 17:02:38 +00:00
|
|
|
s->tio, &cause) != 0) {
|
|
|
|
environ_free(env);
|
2010-01-07 20:52:18 +00:00
|
|
|
goto error;
|
2017-03-09 17:02:38 +00:00
|
|
|
}
|
|
|
|
environ_free(env);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2009-06-01 22:58:49 +00:00
|
|
|
server_redraw_window(w);
|
|
|
|
|
2011-01-04 00:42:46 +00:00
|
|
|
if (!args_has(args, 'd')) {
|
2010-01-07 19:47:10 +00:00
|
|
|
window_set_active_pane(w, new_wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
session_select(s, wl->idx);
|
2017-08-30 10:33:57 +00:00
|
|
|
cmd_find_from_session(current, s, 0);
|
2009-06-01 22:58:49 +00:00
|
|
|
server_redraw_session(s);
|
|
|
|
} else
|
|
|
|
server_status_session(s);
|
|
|
|
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(args, 'P')) {
|
2012-05-22 11:35:37 +00:00
|
|
|
if ((template = args_get(args, 'F')) == NULL)
|
2012-08-14 08:51:53 +00:00
|
|
|
template = SPLIT_WINDOW_TEMPLATE;
|
2017-03-08 13:36:12 +00:00
|
|
|
cp = format_single(item, template, c, s, wl, new_wp);
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s", cp);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(cp);
|
2011-01-01 01:33:07 +00:00
|
|
|
}
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2013-10-10 12:26:34 +00:00
|
|
|
|
2017-08-30 10:33:57 +00:00
|
|
|
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
2016-10-16 19:04:05 +00:00
|
|
|
hooks_insert(s->hooks, item, &fs, "after-split-window");
|
2016-10-16 17:55:14 +00:00
|
|
|
|
2018-03-01 12:53:08 +00:00
|
|
|
free(cwd);
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
error:
|
2015-04-26 20:25:20 +00:00
|
|
|
if (new_wp != NULL) {
|
|
|
|
layout_close_pane(new_wp);
|
2010-01-07 19:47:10 +00:00
|
|
|
window_remove_pane(w, new_wp);
|
2015-04-26 20:25:20 +00:00
|
|
|
}
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "create pane failed: %s", cause);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(cause);
|
2015-10-31 08:13:58 +00:00
|
|
|
|
2018-03-01 12:53:08 +00:00
|
|
|
free(cwd);
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|