Hi, I have been playing with adding a percent option to resize-pane. It's
on the todo list (small things) for tmux, and I find it very useful. Right
now it's working for me but being new to tmux code I would love to have
some eyes on it. I have attached my changes.
If this is worthwhile/useful then I can do it properly via github. In that
case any advice on the proper procedure is welcome!
Anindya
--
You received this message because you are subscribed to the Google Groups
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/tmux-users/CAN%2Bi5iO9yh4TSNJ_r7397%2BCwW55%2BwHqDOs20CBYpFmoXeZfHTA%40mail.gmail.com.
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c
index 8d35d96f..ac2bffd9 100644
--- a/cmd-resize-pane.c
+++ b/cmd-resize-pane.c
@@ -35,9 +35,9 @@ const struct cmd_entry cmd_resize_pane_entry = {
.name = "resize-pane",
.alias = "resizep",
- .args = { "DLMRt:Ux:y:Z", 0, 1 },
+ .args = { "DLMp:Rt:Ux:y:Z", 0, 1 },
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
- "[adjustment]",
+ "[-p percent] [adjustment]",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -57,8 +57,9 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = item->target.s;
const char *errstr;
char *cause;
- u_int adjust;
+ u_int adjust = 0U;
int x, y;
+ u_int percent = 0U;
if (args_has(args, 'M')) {
if (cmd_mouse_window(&shared->mouse, &s) == NULL)
@@ -81,7 +82,21 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item
*item)
}
server_unzoom_window(w);
- if (args->argc == 0)
+ if (args_has(args, 'p')) {
+ percent = args_strtonum(args, 'p', 1, 100, &cause);
+ if (cause != NULL) {
+ cmdq_error(item, "percentage %s", cause);
+ free(cause);
+ return (CMD_RETURN_ERROR);
+ }
+
+ /* Should not also have an adjustment in this case. */
+ if (args->argc > 0) {
+ cmdq_error(item, "percentage and adjustment are
mutually exclusive");
+ return (CMD_RETURN_ERROR);
+ }
+ }
+ else if (args->argc == 0)
adjust = 1;
else {
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
@@ -110,14 +125,26 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item
*item)
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
}
- if (args_has(args, 'L'))
+ if (args_has(args, 'L')) {
+ if (percent > 0)
+ adjust = wp->sx * percent / 100; /* Calculate
adjustment from existing size. */
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust, 1);
- else if (args_has(args, 'R'))
+ }
+ else if (args_has(args, 'R')) {
+ if (percent > 0)
+ adjust = wp->sx * percent / 100;
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust, 1);
- else if (args_has(args, 'U'))
+ }
+ else if (args_has(args, 'U')) {
+ if (percent > 0)
+ adjust = wp->sy * percent / 100;
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust, 1);
- else if (args_has(args, 'D'))
+ }
+ else if (args_has(args, 'D')) {
+ if (percent > 0)
+ adjust = wp->sy * percent / 100;
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust, 1);
+ }
server_redraw_window(wl->window);
return (CMD_RETURN_NORMAL);
diff --git a/tmux.1 b/tmux.1
index e095ba40..98de1a8c 100644
--- a/tmux.1
+++ b/tmux.1
@@ -2224,13 +2224,18 @@ if specified, to
.Ar new-name .
.It Xo Ic resize-pane
.Op Fl DLMRUZ
+.Op Fl p Ar percentage
.Op Fl t Ar target-pane
.Op Fl x Ar width
.Op Fl y Ar height
.Op Ar adjustment
.Xc
.D1 (alias: Ic resizep )
-Resize a pane, up, down, left or right by
+Resize a pane, up, down, left or right by a
+.Ar percentage
+of the current width or height with
+.Fl p
+or by
.Ar adjustment
with
.Fl U ,
@@ -2245,8 +2250,14 @@ with
or
.Fl y .
The
+.Ar percentage
+is an integer between 1 and 100. The
.Ar adjustment
-is given in lines or cells (the default is 1).
+is given in lines or cells (the default is 1). The
+.Ar percentage
+and the
+.Ar adjustment
+are mutually exclusive.
.Pp
With
.Fl Z ,