├── .gitignore ├── CHANGES ├── FAQ ├── Makefile.am ├── NOTES ├── SYNCING ├── TODO ├── arguments.c ├── array.h ├── attributes.c ├── autogen.sh ├── cfg.c ├── client.c ├── clock.c ├── cmd-attach-session.c ├── cmd-bind-key.c ├── cmd-break-pane.c ├── cmd-capture-pane.c ├── cmd-choose-buffer.c ├── cmd-choose-client.c ├── cmd-choose-list.c ├── cmd-choose-tree.c ├── cmd-clear-history.c ├── cmd-clock-mode.c ├── cmd-command-prompt.c ├── cmd-confirm-before.c ├── cmd-copy-mode.c ├── cmd-delete-buffer.c ├── cmd-detach-client.c ├── cmd-display-message.c ├── cmd-display-panes.c ├── cmd-find-window.c ├── cmd-has-session.c ├── cmd-if-shell.c ├── cmd-join-pane.c ├── cmd-kill-pane.c ├── cmd-kill-server.c ├── cmd-kill-session.c ├── cmd-kill-window.c ├── cmd-link-window.c ├── cmd-list-buffers.c ├── cmd-list-clients.c ├── cmd-list-commands.c ├── cmd-list-keys.c ├── cmd-list-panes.c ├── cmd-list-sessions.c ├── cmd-list-windows.c ├── cmd-list.c ├── cmd-load-buffer.c ├── cmd-lock-server.c ├── cmd-move-window.c ├── cmd-new-session.c ├── cmd-new-window.c ├── cmd-paste-buffer.c ├── cmd-pipe-pane.c ├── cmd-refresh-client.c ├── cmd-rename-session.c ├── cmd-rename-window.c ├── cmd-resize-pane.c ├── cmd-respawn-pane.c ├── cmd-respawn-window.c ├── cmd-rotate-window.c ├── cmd-run-shell.c ├── cmd-save-buffer.c ├── cmd-select-layout.c ├── cmd-select-pane.c ├── cmd-select-window.c ├── cmd-send-keys.c ├── cmd-send-prefix.c ├── cmd-server-info.c ├── cmd-set-buffer.c ├── cmd-set-environment.c ├── cmd-set-option.c ├── cmd-show-buffer.c ├── cmd-show-environment.c ├── cmd-show-messages.c ├── cmd-show-options.c ├── cmd-source-file.c ├── cmd-split-window.c ├── cmd-start-server.c ├── cmd-string.c ├── cmd-suspend-client.c ├── cmd-swap-pane.c ├── cmd-swap-window.c ├── cmd-switch-client.c ├── cmd-unbind-key.c ├── cmd-unlink-window.c ├── cmd.c ├── colour.c ├── compat.h ├── compat ├── asprintf.c ├── b64_ntop.c ├── bitstring.h ├── closefrom.c ├── daemon.c ├── fgetln.c ├── forkpty-aix.c ├── forkpty-hpux.c ├── forkpty-sunos.c ├── getopt.c ├── imsg-buffer.c ├── imsg.c ├── imsg.h ├── queue.h ├── setenv.c ├── strcasestr.c ├── strlcat.c ├── strlcpy.c ├── strsep.c ├── strtonum.c ├── tree.h ├── unvis.c ├── vis.c └── vis.h ├── configure.ac ├── control-notify.c ├── control.c ├── environ.c ├── examples ├── bash_completion_tmux.sh ├── h-boetes.conf ├── n-marriott.conf ├── screen-keys.conf ├── t-williams.conf ├── tmux-zoom.sh ├── tmux.vim ├── tmux_backup.sh └── vim-keys.conf ├── format.c ├── grid-utf8.c ├── grid-view.c ├── grid.c ├── input-keys.c ├── input.c ├── job.c ├── key-bindings.c ├── key-string.c ├── layout-custom.c ├── layout-set.c ├── layout.c ├── log.c ├── mode-key.c ├── names.c ├── notify.c ├── options-table.c ├── options.c ├── osdep-aix.c ├── osdep-darwin.c ├── osdep-dragonfly.c ├── osdep-freebsd.c ├── osdep-hpux.c ├── osdep-linux.c ├── osdep-netbsd.c ├── osdep-openbsd.c ├── osdep-sunos.c ├── osdep-unknown.c ├── paste.c ├── resize.c ├── screen-redraw.c ├── screen-write.c ├── screen.c ├── server-client.c ├── server-fn.c ├── server-window.c ├── server.c ├── session.c ├── signal.c ├── status.c ├── tmux.1 ├── tmux.c ├── tmux.h ├── tools ├── 256colors.pl ├── UTF-8-demo.txt ├── ansicode.txt ├── check-compat.sh ├── cmp-cvs.sh ├── fix-ids.sh ├── fuzz.c └── putty-utf8.sh ├── tty-acs.c ├── tty-keys.c ├── tty-term.c ├── tty.c ├── utf8.c ├── window-choose.c ├── window-clock.c ├── window-copy.c ├── window.c ├── www ├── images │ ├── tmux3.png │ ├── tmux4.png │ └── tmux5.png ├── index.html.in └── main.css ├── xmalloc.c └── xterm-keys.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | .deps/ 4 | aclocal.m4 5 | autom4te.cache/ 6 | config.log 7 | config.status 8 | etc/ 9 | tmux 10 | Makefile 11 | Makefile.in 12 | configure 13 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | Welcome to tmux! 2 | 3 | tmux is a "terminal multiplexer", it enables a number of terminals (or windows) 4 | to be accessed and controlled from a single terminal. tmux is intended to be a 5 | simple, modern, BSD-licensed alternative to programs such as GNU screen. 6 | 7 | This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still 8 | run on Solaris and AIX (although they haven't been tested in a while). It is 9 | usable, although there remain a number of missing features and some remaining 10 | bugs are expected. 11 | 12 | If upgrading from 1.5, PLEASE NOTE: 13 | - The word-separators window option is now a session option. 14 | - The options used to change the window attributes when an alert occurs were 15 | removed. Each kind of alert has its own individual set of options. 16 | - The ability to have a list of prefix keys was dropped in favour of two 17 | separate options, prefix and prefix2. 18 | 19 | Since the 1.2 release tmux depends on libevent. Download it from: 20 | 21 | http://www.monkey.org/~provos/libevent/ 22 | 23 | To build tmux from a release tarball, do: 24 | 25 | $ ./configure && make 26 | $ sudo make install 27 | 28 | To build from a version control checkout, the configure script must be 29 | generated by running: 30 | 31 | $ sh autogen.sh 32 | 33 | tmux consists of a server part and multiple clients. The server is created when 34 | required and runs continuously unless killed by the user. Clients access the 35 | server through a socket in /tmp. Multiple sessions may be created on a single 36 | server and attached to a number of clients. Each session may then have a number 37 | of windows and windows may be linked to a number of sessions. Commands are 38 | available to create, rename and destroy windows and sessions; to attach and 39 | detach sessions from client terminals; to set configuration options; to split 40 | windows into several simultaneously displayed panes; and to bind and unbind 41 | command keys (invoked preceded by a prefix key, by default ctrl-b). Please see 42 | the tmux(1) man page for further information. 43 | 44 | A more extensive, but rough, todo list is included in the TODO file. 45 | 46 | tmux also depends on several features of the client terminal (TERM), if these 47 | are missing it may refuse to run, or not behave correctly. 48 | 49 | A Vim syntax file is available in the examples directory. To install it: 50 | 51 | - Drop the file in the syntax directory in your runtimepath (such as 52 | ~/.vim/syntax/tmux.vim). 53 | - Make the filetype recognisable by adding the following to filetype.vim 54 | in your runtimepath (~/.vim/filetype.vim): 55 | 56 | augroup filetypedetect 57 | au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux 58 | augroup END 59 | 60 | - Switch on syntax highlighting by adding "syntax enable" to your vimrc file. 61 | 62 | For debugging, running tmux with -v or -vv will generate server and client log 63 | files in the current directory. 64 | 65 | tmux mailing lists are available; visit: 66 | 67 | https://sourceforge.net/mail/?group_id=200378 68 | 69 | Bug reports, feature suggestions and especially code contributions are most 70 | welcome. Please send by email to: 71 | 72 | nicm@users.sf.net 73 | 74 | This file and the CHANGES, FAQ and TODO files are licensed under the ISC 75 | license. Files under examples/ remain copyright their authors unless otherwise 76 | stated in the file but permission has been received to distribute them with 77 | tmux. All other files have a license and copyright notice at their 78 | start. Please contact me with any queries. 79 | 80 | -- Nicholas Marriott 81 | 82 | $Id$ 83 | -------------------------------------------------------------------------------- /attributes.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Joshua Elsasser 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | const char * 26 | attributes_tostring(u_char attr) 27 | { 28 | static char buf[128]; 29 | size_t len; 30 | 31 | if (attr == 0) 32 | return ("none"); 33 | 34 | len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s", 35 | attr & GRID_ATTR_BRIGHT ? "bright," : "", 36 | attr & GRID_ATTR_DIM ? "dim," : "", 37 | attr & GRID_ATTR_UNDERSCORE ? "underscore," : "", 38 | attr & GRID_ATTR_BLINK ? "blink," : "", 39 | attr & GRID_ATTR_REVERSE ? "reverse," : "", 40 | attr & GRID_ATTR_HIDDEN ? "hidden," : "", 41 | attr & GRID_ATTR_ITALICS ? "italics," : ""); 42 | if (len > 0) 43 | buf[len - 1] = '\0'; 44 | 45 | return (buf); 46 | } 47 | 48 | int 49 | attributes_fromstring(const char *str) 50 | { 51 | const char delimiters[] = " ,|"; 52 | u_char attr; 53 | size_t end; 54 | 55 | if (*str == '\0' || strcspn(str, delimiters) == 0) 56 | return (-1); 57 | if (strchr(delimiters, str[strlen(str) - 1]) != NULL) 58 | return (-1); 59 | 60 | if (strcasecmp(str, "default") == 0 || strcasecmp(str, "none") == 0) 61 | return (0); 62 | 63 | attr = 0; 64 | do { 65 | end = strcspn(str, delimiters); 66 | if ((end == 6 && strncasecmp(str, "bright", end) == 0) || 67 | (end == 4 && strncasecmp(str, "bold", end) == 0)) 68 | attr |= GRID_ATTR_BRIGHT; 69 | else if (end == 3 && strncasecmp(str, "dim", end) == 0) 70 | attr |= GRID_ATTR_DIM; 71 | else if (end == 10 && strncasecmp(str, "underscore", end) == 0) 72 | attr |= GRID_ATTR_UNDERSCORE; 73 | else if (end == 5 && strncasecmp(str, "blink", end) == 0) 74 | attr |= GRID_ATTR_BLINK; 75 | else if (end == 7 && strncasecmp(str, "reverse", end) == 0) 76 | attr |= GRID_ATTR_REVERSE; 77 | else if (end == 6 && strncasecmp(str, "hidden", end) == 0) 78 | attr |= GRID_ATTR_HIDDEN; 79 | else if (end == 7 && strncasecmp(str, "italics", end) == 0) 80 | attr |= GRID_ATTR_ITALICS; 81 | else 82 | return (-1); 83 | str += end + strspn(str + end, delimiters); 84 | } while (*str != '\0'); 85 | 86 | return (attr); 87 | } 88 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | 4 | [ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10 5 | [ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65 6 | 7 | die() 8 | { 9 | echo "$@" >&2 10 | exit 1 11 | } 12 | 13 | mkdir -p etc 14 | aclocal || die "aclocal failed" 15 | automake --add-missing --force-missing --copy --foreign || die "automake failed" 16 | autoreconf || die "autoreconf failed" 17 | -------------------------------------------------------------------------------- /cmd-attach-session.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Attach existing session to the current terminal. 27 | */ 28 | 29 | enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_attach_session_entry = { 32 | "attach-session", "attach", 33 | "drt:", 0, 0, 34 | "[-dr] " CMD_TARGET_SESSION_USAGE, 35 | CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, 36 | NULL, 37 | NULL, 38 | cmd_attach_session_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct session *s; 46 | struct client *c; 47 | const char *update; 48 | char *cause; 49 | u_int i; 50 | 51 | if (RB_EMPTY(&sessions)) { 52 | ctx->error(ctx, "no sessions"); 53 | return (CMD_RETURN_ERROR); 54 | } 55 | 56 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL) 57 | return (CMD_RETURN_ERROR); 58 | 59 | if (ctx->cmdclient == NULL && ctx->curclient == NULL) 60 | return (CMD_RETURN_NORMAL); 61 | 62 | if (ctx->cmdclient == NULL) { 63 | if (args_has(self->args, 'd')) { 64 | /* 65 | * Can't use server_write_session in case attaching to 66 | * the same session as currently attached to. 67 | */ 68 | for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 69 | c = ARRAY_ITEM(&clients, i); 70 | if (c == NULL || c->session != s) 71 | continue; 72 | if (c == ctx->curclient) 73 | continue; 74 | server_write_client(c, MSG_DETACH, NULL, 0); 75 | } 76 | } 77 | 78 | ctx->curclient->session = s; 79 | notify_attached_session_changed(ctx->curclient); 80 | session_update_activity(s); 81 | server_redraw_client(ctx->curclient); 82 | s->curw->flags &= ~WINLINK_ALERTFLAGS; 83 | } else { 84 | if (server_client_open(ctx->cmdclient, s, &cause) != 0) { 85 | ctx->error(ctx, "open terminal failed: %s", cause); 86 | free(cause); 87 | return (CMD_RETURN_ERROR); 88 | } 89 | 90 | if (args_has(self->args, 'r')) 91 | ctx->cmdclient->flags |= CLIENT_READONLY; 92 | 93 | if (args_has(self->args, 'd')) 94 | server_write_session(s, MSG_DETACH, NULL, 0); 95 | 96 | ctx->cmdclient->session = s; 97 | notify_attached_session_changed(ctx->cmdclient); 98 | session_update_activity(s); 99 | server_write_ready(ctx->cmdclient); 100 | 101 | update = options_get_string(&s->options, "update-environment"); 102 | environ_update(update, &ctx->cmdclient->environ, &s->environ); 103 | 104 | server_redraw_client(ctx->cmdclient); 105 | s->curw->flags &= ~WINLINK_ALERTFLAGS; 106 | } 107 | recalculate_sizes(); 108 | server_update_socket(); 109 | 110 | return (CMD_RETURN_ATTACH); 111 | } 112 | -------------------------------------------------------------------------------- /cmd-break-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Break pane off into a window. 27 | */ 28 | 29 | enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_break_pane_entry = { 32 | "break-pane", "breakp", 33 | "dPF:t:", 0, 0, 34 | "[-dP] [-F format] " CMD_TARGET_PANE_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_break_pane_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct winlink *wl; 46 | struct session *s; 47 | struct window_pane *wp; 48 | struct window *w; 49 | char *name; 50 | char *cause; 51 | int base_idx; 52 | struct client *c; 53 | struct format_tree *ft; 54 | const char *template; 55 | char *cp; 56 | 57 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) 58 | return (CMD_RETURN_ERROR); 59 | 60 | if (window_count_panes(wl->window) == 1) { 61 | ctx->error(ctx, "can't break with only one pane"); 62 | return (CMD_RETURN_ERROR); 63 | } 64 | 65 | w = wl->window; 66 | TAILQ_REMOVE(&w->panes, wp, entry); 67 | if (wp == w->active) { 68 | w->active = w->last; 69 | w->last = NULL; 70 | if (w->active == NULL) { 71 | w->active = TAILQ_PREV(wp, window_panes, entry); 72 | if (w->active == NULL) 73 | w->active = TAILQ_NEXT(wp, entry); 74 | } 75 | } else if (wp == w->last) 76 | w->last = NULL; 77 | layout_close_pane(wp); 78 | 79 | w = wp->window = window_create1(s->sx, s->sy); 80 | TAILQ_INSERT_HEAD(&w->panes, wp, entry); 81 | w->active = wp; 82 | name = default_window_name(w); 83 | window_set_name(w, name); 84 | free(name); 85 | layout_init(w); 86 | 87 | base_idx = options_get_number(&s->options, "base-index"); 88 | wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */ 89 | if (!args_has(self->args, 'd')) 90 | session_select(s, wl->idx); 91 | 92 | server_redraw_session(s); 93 | server_status_session_group(s); 94 | 95 | if (args_has(args, 'P')) { 96 | 97 | if ((template = args_get(args, 'F')) == NULL) 98 | template = BREAK_PANE_TEMPLATE; 99 | 100 | ft = format_create(); 101 | if ((c = cmd_find_client(ctx, NULL)) != NULL) 102 | format_client(ft, c); 103 | format_session(ft, s); 104 | format_winlink(ft, s, wl); 105 | format_window_pane(ft, wp); 106 | 107 | cp = format_expand(ft, template); 108 | ctx->print(ctx, "%s", cp); 109 | free(cp); 110 | 111 | format_free(ft); 112 | } 113 | return (CMD_RETURN_NORMAL); 114 | } 115 | -------------------------------------------------------------------------------- /cmd-capture-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Jonathan Alvarado 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Write the entire contents of a pane to a buffer. 28 | */ 29 | 30 | enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_capture_pane_entry = { 33 | "capture-pane", "capturep", 34 | "b:E:S:t:", 0, 0, 35 | "[-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_capture_pane_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct window_pane *wp; 47 | char *buf, *line, *cause; 48 | struct screen *s; 49 | struct grid *gd; 50 | int buffer, n; 51 | u_int i, limit, top, bottom, tmp; 52 | size_t len, linelen; 53 | 54 | if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) 55 | return (CMD_RETURN_ERROR); 56 | s = &wp->base; 57 | gd = s->grid; 58 | 59 | buf = NULL; 60 | len = 0; 61 | 62 | n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause); 63 | if (cause != NULL) { 64 | top = gd->hsize; 65 | free(cause); 66 | } else if (n < 0 && (u_int) -n > gd->hsize) 67 | top = 0; 68 | else 69 | top = gd->hsize + n; 70 | if (top > gd->hsize + gd->sy - 1) 71 | top = gd->hsize + gd->sy - 1; 72 | 73 | n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause); 74 | if (cause != NULL) { 75 | bottom = gd->hsize + gd->sy - 1; 76 | free(cause); 77 | } else if (n < 0 && (u_int) -n > gd->hsize) 78 | bottom = 0; 79 | else 80 | bottom = gd->hsize + n; 81 | if (bottom > gd->hsize + gd->sy - 1) 82 | bottom = gd->hsize + gd->sy - 1; 83 | 84 | if (bottom < top) { 85 | tmp = bottom; 86 | bottom = top; 87 | top = tmp; 88 | } 89 | 90 | for (i = top; i <= bottom; i++) { 91 | line = grid_string_cells(s->grid, 0, i, screen_size_x(s)); 92 | linelen = strlen(line); 93 | 94 | buf = xrealloc(buf, 1, len + linelen + 1); 95 | memcpy(buf + len, line, linelen); 96 | len += linelen; 97 | buf[len++] = '\n'; 98 | 99 | free(line); 100 | } 101 | 102 | limit = options_get_number(&global_options, "buffer-limit"); 103 | 104 | if (!args_has(args, 'b')) { 105 | paste_add(&global_buffers, buf, len, limit); 106 | return (CMD_RETURN_NORMAL); 107 | } 108 | 109 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 110 | if (cause != NULL) { 111 | ctx->error(ctx, "buffer %s", cause); 112 | free(buf); 113 | free(cause); 114 | return (CMD_RETURN_ERROR); 115 | } 116 | 117 | if (paste_replace(&global_buffers, buffer, buf, len) != 0) { 118 | ctx->error(ctx, "no buffer %d", buffer); 119 | free(buf); 120 | return (CMD_RETURN_ERROR); 121 | } 122 | 123 | return (CMD_RETURN_NORMAL); 124 | } 125 | -------------------------------------------------------------------------------- /cmd-choose-list.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2012 Thomas Adam 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include "tmux.h" 27 | 28 | #define CMD_CHOOSE_LIST_DEFAULT_TEMPLATE "run-shell '%%'" 29 | 30 | /* 31 | * Enter choose mode to choose a custom list. 32 | */ 33 | 34 | enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_ctx *); 35 | 36 | void cmd_choose_list_callback(struct window_choose_data *); 37 | void cmd_choose_list_free(struct window_choose_data *); 38 | 39 | const struct cmd_entry cmd_choose_list_entry = { 40 | "choose-list", NULL, 41 | "l:t:", 0, 1, 42 | "[-l items] " CMD_TARGET_WINDOW_USAGE "[template]", 43 | 0, 44 | NULL, 45 | NULL, 46 | cmd_choose_list_exec 47 | }; 48 | 49 | enum cmd_retval 50 | cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx) 51 | { 52 | struct args *args = self->args; 53 | struct winlink *wl; 54 | const char *list1; 55 | char *template, *item, *copy, *list; 56 | u_int idx; 57 | 58 | if (ctx->curclient == NULL) { 59 | ctx->error(ctx, "must be run interactively"); 60 | return (CMD_RETURN_ERROR); 61 | } 62 | 63 | if ((list1 = args_get(args, 'l')) == NULL) 64 | return (CMD_RETURN_ERROR); 65 | 66 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) 67 | return (CMD_RETURN_ERROR); 68 | 69 | if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) 70 | return (CMD_RETURN_NORMAL); 71 | 72 | if (args->argc != 0) 73 | template = xstrdup(args->argv[0]); 74 | else 75 | template = xstrdup(CMD_CHOOSE_LIST_DEFAULT_TEMPLATE); 76 | 77 | copy = list = xstrdup(list1); 78 | idx = 0; 79 | while ((item = strsep(&list, ",")) != NULL) 80 | { 81 | if (*item == '\0') /* no empty entries */ 82 | continue; 83 | window_choose_add_item(wl->window->active, ctx, wl, item, 84 | template, idx); 85 | idx++; 86 | } 87 | free(copy); 88 | 89 | if (idx == 0) { 90 | free(template); 91 | window_pane_reset_mode(wl->window->active); 92 | return (CMD_RETURN_ERROR); 93 | } 94 | 95 | window_choose_ready(wl->window->active, 0, cmd_choose_list_callback, 96 | cmd_choose_list_free); 97 | 98 | free(template); 99 | 100 | return (CMD_RETURN_NORMAL); 101 | } 102 | 103 | void 104 | cmd_choose_list_callback(struct window_choose_data *cdata) 105 | { 106 | if (cdata == NULL || (cdata->client->flags & CLIENT_DEAD)) 107 | return; 108 | 109 | window_choose_ctx(cdata); 110 | } 111 | 112 | void 113 | cmd_choose_list_free(struct window_choose_data *cdata) 114 | { 115 | cdata->session->references--; 116 | cdata->client->references--; 117 | 118 | free(cdata->ft_template); 119 | free(cdata->command); 120 | format_free(cdata->ft); 121 | free(cdata); 122 | 123 | } 124 | -------------------------------------------------------------------------------- /cmd-clear-history.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Clear pane history. 25 | */ 26 | 27 | enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_clear_history_entry = { 30 | "clear-history", "clearhist", 31 | "t:", 0, 0, 32 | CMD_TARGET_PANE_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_clear_history_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct window_pane *wp; 44 | struct grid *gd; 45 | 46 | if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) 47 | return (CMD_RETURN_ERROR); 48 | gd = wp->base.grid; 49 | 50 | grid_move_lines(gd, 0, gd->hsize, gd->sy); 51 | gd->hsize = 0; 52 | 53 | return (CMD_RETURN_NORMAL); 54 | } 55 | -------------------------------------------------------------------------------- /cmd-clock-mode.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Enter clock mode. 25 | */ 26 | 27 | enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_clock_mode_entry = { 30 | "clock-mode", NULL, 31 | "t:", 0, 0, 32 | CMD_TARGET_PANE_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_clock_mode_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct window_pane *wp; 44 | 45 | if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) 46 | return (CMD_RETURN_ERROR); 47 | 48 | window_pane_set_mode(wp, &window_clock_mode); 49 | 50 | return (CMD_RETURN_NORMAL); 51 | } 52 | -------------------------------------------------------------------------------- /cmd-copy-mode.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Enter copy mode. 25 | */ 26 | 27 | void cmd_copy_mode_key_binding(struct cmd *, int); 28 | enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *); 29 | 30 | const struct cmd_entry cmd_copy_mode_entry = { 31 | "copy-mode", NULL, 32 | "t:u", 0, 0, 33 | "[-u] " CMD_TARGET_PANE_USAGE, 34 | 0, 35 | cmd_copy_mode_key_binding, 36 | NULL, 37 | cmd_copy_mode_exec 38 | }; 39 | 40 | void 41 | cmd_copy_mode_key_binding(struct cmd *self, int key) 42 | { 43 | self->args = args_create(0); 44 | if (key == KEYC_PPAGE) 45 | args_set(self->args, 'u', NULL); 46 | } 47 | 48 | enum cmd_retval 49 | cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx) 50 | { 51 | struct args *args = self->args; 52 | struct window_pane *wp; 53 | 54 | if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) 55 | return (CMD_RETURN_ERROR); 56 | 57 | if (window_pane_set_mode(wp, &window_copy_mode) != 0) 58 | return (CMD_RETURN_NORMAL); 59 | window_copy_init_from_pane(wp); 60 | if (wp->mode == &window_copy_mode && args_has(self->args, 'u')) 61 | window_copy_pageup(wp); 62 | 63 | return (CMD_RETURN_NORMAL); 64 | } 65 | -------------------------------------------------------------------------------- /cmd-delete-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Delete a paste buffer. 27 | */ 28 | 29 | enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_delete_buffer_entry = { 32 | "delete-buffer", "deleteb", 33 | "b:", 0, 0, 34 | CMD_BUFFER_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_delete_buffer_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | char *cause; 46 | int buffer; 47 | 48 | if (!args_has(args, 'b')) { 49 | paste_free_top(&global_buffers); 50 | return (CMD_RETURN_NORMAL); 51 | } 52 | 53 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 54 | if (cause != NULL) { 55 | ctx->error(ctx, "buffer %s", cause); 56 | free(cause); 57 | return (CMD_RETURN_ERROR); 58 | } 59 | 60 | if (paste_free_index(&global_buffers, buffer) != 0) { 61 | ctx->error(ctx, "no buffer %d", buffer); 62 | return (CMD_RETURN_ERROR); 63 | } 64 | 65 | return (CMD_RETURN_NORMAL); 66 | } 67 | -------------------------------------------------------------------------------- /cmd-detach-client.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Detach a client. 25 | */ 26 | 27 | enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_detach_client_entry = { 30 | "detach-client", "detach", 31 | "as:t:P", 0, 0, 32 | "[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE, 33 | CMD_READONLY, 34 | NULL, 35 | NULL, 36 | cmd_detach_client_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct client *c, *c2; 44 | struct session *s; 45 | enum msgtype msgtype; 46 | u_int i; 47 | 48 | if (args_has(args, 'P')) 49 | msgtype = MSG_DETACHKILL; 50 | else 51 | msgtype = MSG_DETACH; 52 | 53 | if (args_has(args, 's')) { 54 | s = cmd_find_session(ctx, args_get(args, 's'), 0); 55 | if (s == NULL) 56 | return (CMD_RETURN_ERROR); 57 | 58 | for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 59 | c = ARRAY_ITEM(&clients, i); 60 | if (c != NULL && c->session == s) 61 | server_write_client(c, msgtype, NULL, 0); 62 | } 63 | } else { 64 | c = cmd_find_client(ctx, args_get(args, 't')); 65 | if (c == NULL) 66 | return (CMD_RETURN_ERROR); 67 | 68 | if (args_has(args, 'a')) { 69 | for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 70 | c2 = ARRAY_ITEM(&clients, i); 71 | if (c2 == NULL || c == c2) 72 | continue; 73 | server_write_client(c2, msgtype, NULL, 0); 74 | } 75 | } else 76 | server_write_client(c, msgtype, NULL, 0); 77 | } 78 | 79 | return (CMD_RETURN_NORMAL); 80 | } 81 | -------------------------------------------------------------------------------- /cmd-display-message.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Tiago Cunha 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Displays a message in the status line. 28 | */ 29 | 30 | enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_display_message_entry = { 33 | "display-message", "display", 34 | "c:pt:F:", 0, 1, 35 | "[-p] [-c target-client] [-t target-pane] [-F format] [message]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_display_message_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct client *c; 47 | struct session *s; 48 | struct winlink *wl; 49 | struct window_pane *wp; 50 | const char *template; 51 | char *msg; 52 | struct format_tree *ft; 53 | char out[BUFSIZ]; 54 | time_t t; 55 | size_t len; 56 | 57 | if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) 58 | return (CMD_RETURN_ERROR); 59 | 60 | if (args_has(args, 't')) { 61 | wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); 62 | if (wl == NULL) 63 | return (CMD_RETURN_ERROR); 64 | } else { 65 | wl = cmd_find_pane(ctx, NULL, &s, &wp); 66 | if (wl == NULL) 67 | return (CMD_RETURN_ERROR); 68 | } 69 | 70 | if (args_has(args, 'F') && args->argc != 0) { 71 | ctx->error(ctx, "only one of -F or argument must be given"); 72 | return (CMD_RETURN_ERROR); 73 | } 74 | 75 | template = args_get(args, 'F'); 76 | if (args->argc != 0) 77 | template = args->argv[0]; 78 | if (template == NULL) 79 | template = DISPLAY_MESSAGE_TEMPLATE; 80 | 81 | ft = format_create(); 82 | format_client(ft, c); 83 | format_session(ft, s); 84 | format_winlink(ft, s, wl); 85 | format_window_pane(ft, wp); 86 | 87 | t = time(NULL); 88 | len = strftime(out, sizeof out, template, localtime(&t)); 89 | out[len] = '\0'; 90 | 91 | msg = format_expand(ft, out); 92 | if (args_has(self->args, 'p')) 93 | ctx->print(ctx, "%s", msg); 94 | else 95 | status_message_set(c, "%s", msg); 96 | 97 | free(msg); 98 | format_free(ft); 99 | return (CMD_RETURN_NORMAL); 100 | } 101 | -------------------------------------------------------------------------------- /cmd-display-panes.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Display panes on a client. 25 | */ 26 | 27 | enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_display_panes_entry = { 30 | "display-panes", "displayp", 31 | "t:", 0, 0, 32 | CMD_TARGET_CLIENT_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_display_panes_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct client *c; 44 | 45 | if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) 46 | return (CMD_RETURN_ERROR); 47 | 48 | server_set_identify(c); 49 | 50 | return (CMD_RETURN_NORMAL); 51 | } 52 | -------------------------------------------------------------------------------- /cmd-has-session.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Cause client to report an error and exit with 1 if session doesn't exist. 25 | */ 26 | 27 | enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_has_session_entry = { 30 | "has-session", "has", 31 | "t:", 0, 0, 32 | CMD_TARGET_SESSION_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_has_session_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | 44 | if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL) 45 | return (CMD_RETURN_ERROR); 46 | 47 | return (CMD_RETURN_NORMAL); 48 | } 49 | -------------------------------------------------------------------------------- /cmd-if-shell.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Tiago Cunha 5 | * Copyright (c) 2009 Nicholas Marriott 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 16 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 17 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "tmux.h" 27 | 28 | /* 29 | * Executes a tmux command if a shell command returns true or false. 30 | */ 31 | 32 | enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_ctx *); 33 | 34 | void cmd_if_shell_callback(struct job *); 35 | void cmd_if_shell_free(void *); 36 | 37 | const struct cmd_entry cmd_if_shell_entry = { 38 | "if-shell", "if", 39 | "", 2, 3, 40 | "shell-command command [command]", 41 | 0, 42 | NULL, 43 | NULL, 44 | cmd_if_shell_exec 45 | }; 46 | 47 | struct cmd_if_shell_data { 48 | char *cmd_if; 49 | char *cmd_else; 50 | struct cmd_ctx ctx; 51 | }; 52 | 53 | enum cmd_retval 54 | cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) 55 | { 56 | struct args *args = self->args; 57 | struct cmd_if_shell_data *cdata; 58 | const char *shellcmd = args->argv[0]; 59 | 60 | cdata = xmalloc(sizeof *cdata); 61 | cdata->cmd_if = xstrdup(args->argv[1]); 62 | if (args->argc == 3) 63 | cdata->cmd_else = xstrdup(args->argv[2]); 64 | else 65 | cdata->cmd_else = NULL; 66 | memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); 67 | 68 | if (ctx->cmdclient != NULL) 69 | ctx->cmdclient->references++; 70 | if (ctx->curclient != NULL) 71 | ctx->curclient->references++; 72 | 73 | job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata); 74 | 75 | return (CMD_RETURN_YIELD); /* don't let client exit */ 76 | } 77 | 78 | void 79 | cmd_if_shell_callback(struct job *job) 80 | { 81 | struct cmd_if_shell_data *cdata = job->data; 82 | struct cmd_ctx *ctx = &cdata->ctx; 83 | struct cmd_list *cmdlist; 84 | char *cause, *cmd; 85 | 86 | if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) { 87 | cmd = cdata->cmd_else; 88 | if (cmd == NULL) 89 | return; 90 | } else 91 | cmd = cdata->cmd_if; 92 | if (cmd_string_parse(cmd, &cmdlist, &cause) != 0) { 93 | if (cause != NULL) { 94 | ctx->error(ctx, "%s", cause); 95 | free(cause); 96 | } 97 | return; 98 | } 99 | 100 | cmd_list_exec(cmdlist, ctx); 101 | cmd_list_free(cmdlist); 102 | } 103 | 104 | void 105 | cmd_if_shell_free(void *data) 106 | { 107 | struct cmd_if_shell_data *cdata = data; 108 | struct cmd_ctx *ctx = &cdata->ctx; 109 | 110 | if (ctx->cmdclient != NULL) { 111 | ctx->cmdclient->references--; 112 | ctx->cmdclient->flags |= CLIENT_EXIT; 113 | } 114 | if (ctx->curclient != NULL) 115 | ctx->curclient->references--; 116 | 117 | free(cdata->cmd_else); 118 | free(cdata->cmd_if); 119 | free(cdata); 120 | } 121 | -------------------------------------------------------------------------------- /cmd-kill-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Kill pane. 27 | */ 28 | 29 | enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_kill_pane_entry = { 32 | "kill-pane", "killp", 33 | "at:", 0, 0, 34 | "[-a] " CMD_TARGET_PANE_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_kill_pane_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct winlink *wl; 46 | struct window_pane *loopwp, *tmpwp, *wp; 47 | 48 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) 49 | return (CMD_RETURN_ERROR); 50 | 51 | if (window_count_panes(wl->window) == 1) { 52 | /* Only one pane, kill the window. */ 53 | server_kill_window(wl->window); 54 | recalculate_sizes(); 55 | return (CMD_RETURN_NORMAL); 56 | } 57 | 58 | if (args_has(self->args, 'a')) { 59 | TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) { 60 | if (loopwp == wp) 61 | continue; 62 | layout_close_pane(loopwp); 63 | window_remove_pane(wl->window, loopwp); 64 | } 65 | } else { 66 | layout_close_pane(wp); 67 | window_remove_pane(wl->window, wp); 68 | } 69 | server_redraw_window(wl->window); 70 | 71 | return (CMD_RETURN_NORMAL); 72 | } 73 | -------------------------------------------------------------------------------- /cmd-kill-server.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Kill the server and do nothing else. 28 | */ 29 | 30 | enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_kill_server_entry = { 33 | "kill-server", NULL, 34 | "", 0, 0, 35 | "", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_kill_server_exec 40 | }; 41 | 42 | /* ARGSUSED */ 43 | enum cmd_retval 44 | cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) 45 | { 46 | kill(getpid(), SIGTERM); 47 | 48 | return (CMD_RETURN_NORMAL); 49 | } 50 | -------------------------------------------------------------------------------- /cmd-kill-session.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Destroy session, detaching all clients attached to it and destroying any 25 | * windows linked only to this session. 26 | * 27 | * Note this deliberately has no alias to make it hard to hit by accident. 28 | */ 29 | 30 | enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_kill_session_entry = { 33 | "kill-session", NULL, 34 | "at:", 0, 0, 35 | "[-a] " CMD_TARGET_SESSION_USAGE, 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_kill_session_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct session *s, *s2, *s3; 47 | 48 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 49 | return (CMD_RETURN_ERROR); 50 | 51 | if (args_has(args, 'a')) { 52 | RB_FOREACH_SAFE(s2, sessions, &sessions, s3) { 53 | if (s != s2) { 54 | server_destroy_session(s2); 55 | session_destroy(s2); 56 | } 57 | } 58 | } else { 59 | server_destroy_session(s); 60 | session_destroy(s); 61 | } 62 | return (CMD_RETURN_NORMAL); 63 | } 64 | -------------------------------------------------------------------------------- /cmd-kill-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Destroy window. 25 | */ 26 | 27 | enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_kill_window_entry = { 30 | "kill-window", "killw", 31 | "at:", 0, 0, 32 | "[-a] " CMD_TARGET_WINDOW_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_kill_window_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct winlink *wl, *wl2, *wl3; 44 | struct session *s; 45 | 46 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) 47 | return (CMD_RETURN_ERROR); 48 | 49 | if (args_has(args, 'a')) { 50 | RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) { 51 | if (wl != wl2) 52 | server_kill_window(wl2->window); 53 | } 54 | } else 55 | server_kill_window(wl->window); 56 | 57 | recalculate_sizes(); 58 | return (CMD_RETURN_NORMAL); 59 | } 60 | -------------------------------------------------------------------------------- /cmd-link-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Link a window into another session. 27 | */ 28 | 29 | enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_link_window_entry = { 32 | "link-window", "linkw", 33 | "dks:t:", 0, 0, 34 | "[-dk] " CMD_SRCDST_WINDOW_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_link_window_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct session *src, *dst; 46 | struct winlink *wl; 47 | char *cause; 48 | int idx, kflag, dflag; 49 | 50 | if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL) 51 | return (CMD_RETURN_ERROR); 52 | if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) 53 | return (CMD_RETURN_ERROR); 54 | 55 | kflag = args_has(self->args, 'k'); 56 | dflag = args_has(self->args, 'd'); 57 | if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { 58 | ctx->error(ctx, "can't link window: %s", cause); 59 | free(cause); 60 | return (CMD_RETURN_ERROR); 61 | } 62 | recalculate_sizes(); 63 | 64 | return (CMD_RETURN_NORMAL); 65 | } 66 | -------------------------------------------------------------------------------- /cmd-list-buffers.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * List paste buffers. 28 | */ 29 | 30 | enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_list_buffers_entry = { 33 | "list-buffers", "lsb", 34 | "F:", 0, 0, 35 | "[-F format]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_list_buffers_exec 40 | }; 41 | 42 | /* ARGSUSED */ 43 | enum cmd_retval 44 | cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx) 45 | { 46 | struct args *args = self->args; 47 | struct paste_buffer *pb; 48 | struct format_tree *ft; 49 | u_int idx; 50 | char *line; 51 | const char *template; 52 | 53 | if ((template = args_get(args, 'F')) == NULL) 54 | template = LIST_BUFFERS_TEMPLATE; 55 | 56 | idx = 0; 57 | while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) { 58 | ft = format_create(); 59 | format_add(ft, "line", "%u", idx - 1); 60 | format_paste_buffer(ft, pb); 61 | 62 | line = format_expand(ft, template); 63 | ctx->print(ctx, "%s", line); 64 | free(line); 65 | 66 | format_free(ft); 67 | } 68 | 69 | return (CMD_RETURN_NORMAL); 70 | } 71 | -------------------------------------------------------------------------------- /cmd-list-clients.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "tmux.h" 26 | 27 | /* 28 | * List all clients. 29 | */ 30 | 31 | int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | const struct cmd_entry cmd_list_clients_entry = { 34 | "list-clients", "lsc", 35 | "F:t:", 0, 0, 36 | "[-F format] " CMD_TARGET_SESSION_USAGE, 37 | CMD_READONLY, 38 | NULL, 39 | NULL, 40 | cmd_list_clients_exec 41 | }; 42 | 43 | /* ARGSUSED */ 44 | enum cmd_retval 45 | cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx) 46 | { 47 | struct args *args = self->args; 48 | struct client *c; 49 | struct session *s; 50 | struct format_tree *ft; 51 | const char *template; 52 | u_int i; 53 | char *line; 54 | 55 | if (args_has(args, 't')) { 56 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 57 | if (s == NULL) 58 | return (CMD_RETURN_ERROR); 59 | } else 60 | s = NULL; 61 | 62 | if ((template = args_get(args, 'F')) == NULL) 63 | template = LIST_CLIENTS_TEMPLATE; 64 | 65 | for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 66 | c = ARRAY_ITEM(&clients, i); 67 | if (c == NULL || c->session == NULL) 68 | continue; 69 | 70 | if (s != NULL && s != c->session) 71 | continue; 72 | 73 | ft = format_create(); 74 | format_add(ft, "line", "%u", i); 75 | format_session(ft, c->session); 76 | format_client(ft, c); 77 | 78 | line = format_expand(ft, template); 79 | ctx->print(ctx, "%s", line); 80 | free(line); 81 | 82 | format_free(ft); 83 | } 84 | 85 | return (CMD_RETURN_NORMAL); 86 | } 87 | -------------------------------------------------------------------------------- /cmd-list-commands.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * List all commands with usages. 25 | */ 26 | 27 | enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_list_commands_entry = { 30 | "list-commands", "lscm", 31 | "", 0, 0, 32 | "", 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_list_commands_exec 37 | }; 38 | 39 | /* ARGSUSED */ 40 | enum cmd_retval 41 | cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx) 42 | { 43 | const struct cmd_entry **entryp; 44 | 45 | for (entryp = cmd_table; *entryp != NULL; entryp++) 46 | ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage); 47 | 48 | return (CMD_RETURN_NORMAL); 49 | } 50 | -------------------------------------------------------------------------------- /cmd-list-sessions.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "tmux.h" 26 | 27 | /* 28 | * List all sessions. 29 | */ 30 | 31 | enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | const struct cmd_entry cmd_list_sessions_entry = { 34 | "list-sessions", "ls", 35 | "F:", 0, 0, 36 | "[-F format]", 37 | 0, 38 | NULL, 39 | NULL, 40 | cmd_list_sessions_exec 41 | }; 42 | 43 | enum cmd_retval 44 | cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx) 45 | { 46 | struct args *args = self->args; 47 | struct session *s; 48 | u_int n; 49 | struct format_tree *ft; 50 | const char *template; 51 | char *line; 52 | 53 | if ((template = args_get(args, 'F')) == NULL) 54 | template = LIST_SESSIONS_TEMPLATE; 55 | 56 | n = 0; 57 | RB_FOREACH(s, sessions, &sessions) { 58 | ft = format_create(); 59 | format_add(ft, "line", "%u", n); 60 | format_session(ft, s); 61 | 62 | line = format_expand(ft, template); 63 | ctx->print(ctx, "%s", line); 64 | free(line); 65 | 66 | format_free(ft); 67 | n++; 68 | } 69 | 70 | return (CMD_RETURN_NORMAL); 71 | } 72 | -------------------------------------------------------------------------------- /cmd-list-windows.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * List windows on given session. 28 | */ 29 | 30 | enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | void cmd_list_windows_server(struct cmd *, struct cmd_ctx *); 33 | void cmd_list_windows_session( 34 | struct cmd *, struct session *, struct cmd_ctx *, int); 35 | 36 | const struct cmd_entry cmd_list_windows_entry = { 37 | "list-windows", "lsw", 38 | "F:at:", 0, 0, 39 | "[-a] [-F format] " CMD_TARGET_SESSION_USAGE, 40 | 0, 41 | NULL, 42 | NULL, 43 | cmd_list_windows_exec 44 | }; 45 | 46 | enum cmd_retval 47 | cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx) 48 | { 49 | struct args *args = self->args; 50 | struct session *s; 51 | 52 | if (args_has(args, 'a')) 53 | cmd_list_windows_server(self, ctx); 54 | else { 55 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 56 | if (s == NULL) 57 | return (CMD_RETURN_ERROR); 58 | cmd_list_windows_session(self, s, ctx, 0); 59 | } 60 | 61 | return (CMD_RETURN_NORMAL); 62 | } 63 | 64 | void 65 | cmd_list_windows_server(struct cmd *self, struct cmd_ctx *ctx) 66 | { 67 | struct session *s; 68 | 69 | RB_FOREACH(s, sessions, &sessions) 70 | cmd_list_windows_session(self, s, ctx, 1); 71 | } 72 | 73 | void 74 | cmd_list_windows_session( 75 | struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type) 76 | { 77 | struct args *args = self->args; 78 | struct winlink *wl; 79 | u_int n; 80 | struct format_tree *ft; 81 | const char *template; 82 | char *line; 83 | 84 | template = args_get(args, 'F'); 85 | if (template == NULL) { 86 | switch (type) { 87 | case 0: 88 | template = LIST_WINDOWS_TEMPLATE; 89 | break; 90 | case 1: 91 | template = LIST_WINDOWS_WITH_SESSION_TEMPLATE; 92 | break; 93 | } 94 | } 95 | 96 | n = 0; 97 | RB_FOREACH(wl, winlinks, &s->windows) { 98 | ft = format_create(); 99 | format_add(ft, "line", "%u", n); 100 | format_session(ft, s); 101 | format_winlink(ft, s, wl); 102 | 103 | line = format_expand(ft, template); 104 | ctx->print(ctx, "%s", line); 105 | free(line); 106 | 107 | format_free(ft); 108 | n++; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /cmd-lock-server.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "tmux.h" 26 | 27 | /* 28 | * Lock commands. 29 | */ 30 | 31 | enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | const struct cmd_entry cmd_lock_server_entry = { 34 | "lock-server", "lock", 35 | "", 0, 0, 36 | "", 37 | 0, 38 | NULL, 39 | NULL, 40 | cmd_lock_server_exec 41 | }; 42 | 43 | const struct cmd_entry cmd_lock_session_entry = { 44 | "lock-session", "locks", 45 | "t:", 0, 0, 46 | CMD_TARGET_SESSION_USAGE, 47 | 0, 48 | NULL, 49 | NULL, 50 | cmd_lock_server_exec 51 | }; 52 | 53 | const struct cmd_entry cmd_lock_client_entry = { 54 | "lock-client", "lockc", 55 | "t:", 0, 0, 56 | CMD_TARGET_CLIENT_USAGE, 57 | 0, 58 | NULL, 59 | NULL, 60 | cmd_lock_server_exec 61 | }; 62 | 63 | /* ARGSUSED */ 64 | enum cmd_retval 65 | cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx) 66 | { 67 | struct args *args = self->args; 68 | struct client *c; 69 | struct session *s; 70 | 71 | if (self->entry == &cmd_lock_server_entry) 72 | server_lock(); 73 | else if (self->entry == &cmd_lock_session_entry) { 74 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 75 | return (CMD_RETURN_ERROR); 76 | server_lock_session(s); 77 | } else { 78 | if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) 79 | return (CMD_RETURN_ERROR); 80 | server_lock_client(c); 81 | } 82 | recalculate_sizes(); 83 | 84 | return (CMD_RETURN_NORMAL); 85 | } 86 | -------------------------------------------------------------------------------- /cmd-move-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Move a window. 27 | */ 28 | 29 | enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_move_window_entry = { 32 | "move-window", "movew", 33 | "dkrs:t:", 0, 0, 34 | "[-dkr] " CMD_SRCDST_WINDOW_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_move_window_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct session *src, *dst, *s; 46 | struct winlink *wl; 47 | char *cause; 48 | int idx, kflag, dflag; 49 | 50 | if (args_has(args, 'r')) { 51 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 52 | return (CMD_RETURN_ERROR); 53 | 54 | session_renumber_windows(s); 55 | recalculate_sizes(); 56 | 57 | return (CMD_RETURN_NORMAL); 58 | } 59 | 60 | if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL) 61 | return (CMD_RETURN_ERROR); 62 | if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) 63 | return (CMD_RETURN_ERROR); 64 | 65 | kflag = args_has(self->args, 'k'); 66 | dflag = args_has(self->args, 'd'); 67 | if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { 68 | ctx->error(ctx, "can't move window: %s", cause); 69 | free(cause); 70 | return (CMD_RETURN_ERROR); 71 | } 72 | server_unlink_window(src, wl); 73 | recalculate_sizes(); 74 | 75 | return (CMD_RETURN_NORMAL); 76 | } 77 | -------------------------------------------------------------------------------- /cmd-refresh-client.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Refresh client. 25 | */ 26 | 27 | enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_refresh_client_entry = { 30 | "refresh-client", "refresh", 31 | "St:", 0, 0, 32 | "[-S] " CMD_TARGET_CLIENT_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_refresh_client_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct client *c; 44 | 45 | if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) 46 | return (CMD_RETURN_ERROR); 47 | 48 | if (args_has(args, 'S')) { 49 | status_update_jobs(c); 50 | server_status_client(c); 51 | } else 52 | server_redraw_client(c); 53 | 54 | return (CMD_RETURN_NORMAL); 55 | } 56 | -------------------------------------------------------------------------------- /cmd-rename-session.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Change session name. 27 | */ 28 | 29 | enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_rename_session_entry = { 32 | "rename-session", "rename", 33 | "t:", 1, 1, 34 | CMD_TARGET_SESSION_USAGE " new-name", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_rename_session_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct session *s; 46 | const char *newname; 47 | 48 | newname = args->argv[0]; 49 | if (!session_check_name(newname)) { 50 | ctx->error(ctx, "bad session name: %s", newname); 51 | return (CMD_RETURN_ERROR); 52 | } 53 | if (session_find(newname) != NULL) { 54 | ctx->error(ctx, "duplicate session: %s", newname); 55 | return (CMD_RETURN_ERROR); 56 | } 57 | 58 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 59 | return (CMD_RETURN_ERROR); 60 | 61 | RB_REMOVE(sessions, &sessions, s); 62 | free(s->name); 63 | s->name = xstrdup(newname); 64 | RB_INSERT(sessions, &sessions, s); 65 | 66 | server_status_session(s); 67 | notify_session_renamed(s); 68 | 69 | return (CMD_RETURN_NORMAL); 70 | } 71 | -------------------------------------------------------------------------------- /cmd-rename-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Rename a window. 27 | */ 28 | 29 | enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_rename_window_entry = { 32 | "rename-window", "renamew", 33 | "t:", 1, 1, 34 | CMD_TARGET_WINDOW_USAGE " new-name", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_rename_window_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct session *s; 46 | struct winlink *wl; 47 | 48 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) 49 | return (CMD_RETURN_ERROR); 50 | 51 | window_set_name(wl->window, args->argv[0]); 52 | options_set_number(&wl->window->options, "automatic-rename", 0); 53 | 54 | server_status_window(wl->window); 55 | 56 | return (CMD_RETURN_NORMAL); 57 | } 58 | -------------------------------------------------------------------------------- /cmd-respawn-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * Copyright (c) 2011 Marcel P. Partap 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 16 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 17 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "tmux.h" 26 | 27 | /* 28 | * Respawn a pane (restart the command). Kill existing if -k given. 29 | */ 30 | 31 | enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | const struct cmd_entry cmd_respawn_pane_entry = { 34 | "respawn-pane", "respawnp", 35 | "kt:", 0, 1, 36 | "[-k] " CMD_TARGET_PANE_USAGE " [command]", 37 | 0, 38 | NULL, 39 | NULL, 40 | cmd_respawn_pane_exec 41 | }; 42 | 43 | enum cmd_retval 44 | cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx) 45 | { 46 | struct args *args = self->args; 47 | struct winlink *wl; 48 | struct window *w; 49 | struct window_pane *wp; 50 | struct session *s; 51 | struct environ env; 52 | const char *cmd; 53 | char *cause; 54 | u_int idx; 55 | 56 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) 57 | return (CMD_RETURN_ERROR); 58 | w = wl->window; 59 | 60 | if (!args_has(self->args, 'k') && wp->fd != -1) { 61 | if (window_pane_index(wp, &idx) != 0) 62 | fatalx("index not found"); 63 | ctx->error(ctx, "pane still active: %s:%u.%u", 64 | s->name, wl->idx, idx); 65 | return (CMD_RETURN_ERROR); 66 | } 67 | 68 | environ_init(&env); 69 | environ_copy(&global_environ, &env); 70 | environ_copy(&s->environ, &env); 71 | server_fill_environ(s, &env); 72 | 73 | window_pane_reset_mode(wp); 74 | screen_reinit(&wp->base); 75 | input_init(wp); 76 | 77 | if (args->argc != 0) 78 | cmd = args->argv[0]; 79 | else 80 | cmd = NULL; 81 | if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) { 82 | ctx->error(ctx, "respawn pane failed: %s", cause); 83 | free(cause); 84 | environ_free(&env); 85 | return (CMD_RETURN_ERROR); 86 | } 87 | wp->flags |= PANE_REDRAW; 88 | server_status_window(w); 89 | 90 | environ_free(&env); 91 | return (CMD_RETURN_NORMAL); 92 | } 93 | -------------------------------------------------------------------------------- /cmd-respawn-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Respawn a window (restart the command). Kill existing if -k given. 28 | */ 29 | 30 | enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_respawn_window_entry = { 33 | "respawn-window", "respawnw", 34 | "kt:", 0, 1, 35 | "[-k] " CMD_TARGET_WINDOW_USAGE " [command]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_respawn_window_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct winlink *wl; 47 | struct window *w; 48 | struct window_pane *wp; 49 | struct session *s; 50 | struct environ env; 51 | const char *cmd; 52 | char *cause; 53 | 54 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) 55 | return (CMD_RETURN_ERROR); 56 | w = wl->window; 57 | 58 | if (!args_has(self->args, 'k')) { 59 | TAILQ_FOREACH(wp, &w->panes, entry) { 60 | if (wp->fd == -1) 61 | continue; 62 | ctx->error(ctx, 63 | "window still active: %s:%d", s->name, wl->idx); 64 | return (CMD_RETURN_ERROR); 65 | } 66 | } 67 | 68 | environ_init(&env); 69 | environ_copy(&global_environ, &env); 70 | environ_copy(&s->environ, &env); 71 | server_fill_environ(s, &env); 72 | 73 | wp = TAILQ_FIRST(&w->panes); 74 | TAILQ_REMOVE(&w->panes, wp, entry); 75 | layout_free(w); 76 | window_destroy_panes(w); 77 | TAILQ_INSERT_HEAD(&w->panes, wp, entry); 78 | window_pane_resize(wp, w->sx, w->sy); 79 | if (args->argc != 0) 80 | cmd = args->argv[0]; 81 | else 82 | cmd = NULL; 83 | if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) { 84 | ctx->error(ctx, "respawn window failed: %s", cause); 85 | free(cause); 86 | environ_free(&env); 87 | server_destroy_pane(wp); 88 | return (CMD_RETURN_ERROR); 89 | } 90 | layout_init(w); 91 | window_pane_reset_mode(wp); 92 | screen_reinit(&wp->base); 93 | input_init(wp); 94 | window_set_active_pane(w, wp); 95 | 96 | recalculate_sizes(); 97 | server_redraw_window(w); 98 | 99 | environ_free(&env); 100 | return (CMD_RETURN_NORMAL); 101 | } 102 | -------------------------------------------------------------------------------- /cmd-save-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Tiago Cunha 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "tmux.h" 27 | 28 | /* 29 | * Saves a paste buffer to a file. 30 | */ 31 | 32 | enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *); 33 | 34 | const struct cmd_entry cmd_save_buffer_entry = { 35 | "save-buffer", "saveb", 36 | "ab:", 1, 1, 37 | "[-a] " CMD_BUFFER_USAGE " path", 38 | 0, 39 | NULL, 40 | NULL, 41 | cmd_save_buffer_exec 42 | }; 43 | 44 | enum cmd_retval 45 | cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 46 | { 47 | struct args *args = self->args; 48 | struct client *c = ctx->cmdclient; 49 | struct session *s; 50 | struct paste_buffer *pb; 51 | const char *path, *newpath, *wd; 52 | char *cause; 53 | int buffer; 54 | mode_t mask; 55 | FILE *f; 56 | 57 | if (!args_has(args, 'b')) { 58 | if ((pb = paste_get_top(&global_buffers)) == NULL) { 59 | ctx->error(ctx, "no buffers"); 60 | return (CMD_RETURN_ERROR); 61 | } 62 | } else { 63 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 64 | if (cause != NULL) { 65 | ctx->error(ctx, "buffer %s", cause); 66 | free(cause); 67 | return (CMD_RETURN_ERROR); 68 | } 69 | 70 | pb = paste_get_index(&global_buffers, buffer); 71 | if (pb == NULL) { 72 | ctx->error(ctx, "no buffer %d", buffer); 73 | return (CMD_RETURN_ERROR); 74 | } 75 | } 76 | 77 | path = args->argv[0]; 78 | if (strcmp(path, "-") == 0) { 79 | if (c == NULL) { 80 | ctx->error(ctx, "%s: can't write to stdout", path); 81 | return (CMD_RETURN_ERROR); 82 | } 83 | evbuffer_add(c->stdout_data, pb->data, pb->size); 84 | server_push_stdout(c); 85 | } else { 86 | if (c != NULL) 87 | wd = c->cwd; 88 | else if ((s = cmd_current_session(ctx, 0)) != NULL) { 89 | wd = options_get_string(&s->options, "default-path"); 90 | if (*wd == '\0') 91 | wd = s->cwd; 92 | } else 93 | wd = NULL; 94 | if (wd != NULL && *wd != '\0') { 95 | newpath = get_full_path(wd, path); 96 | if (newpath != NULL) 97 | path = newpath; 98 | } 99 | 100 | mask = umask(S_IRWXG | S_IRWXO); 101 | if (args_has(self->args, 'a')) 102 | f = fopen(path, "ab"); 103 | else 104 | f = fopen(path, "wb"); 105 | umask(mask); 106 | if (f == NULL) { 107 | ctx->error(ctx, "%s: %s", path, strerror(errno)); 108 | return (CMD_RETURN_ERROR); 109 | } 110 | if (fwrite(pb->data, 1, pb->size, f) != pb->size) { 111 | ctx->error(ctx, "%s: fwrite error", path); 112 | fclose(f); 113 | return (CMD_RETURN_ERROR); 114 | } 115 | fclose(f); 116 | } 117 | 118 | return (CMD_RETURN_NORMAL); 119 | } 120 | -------------------------------------------------------------------------------- /cmd-select-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Select pane. 25 | */ 26 | 27 | void cmd_select_pane_key_binding(struct cmd *, int); 28 | enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_ctx *); 29 | 30 | const struct cmd_entry cmd_select_pane_entry = { 31 | "select-pane", "selectp", 32 | "lDLRt:U", 0, 0, 33 | "[-lDLRU] " CMD_TARGET_PANE_USAGE, 34 | 0, 35 | cmd_select_pane_key_binding, 36 | NULL, 37 | cmd_select_pane_exec 38 | }; 39 | 40 | const struct cmd_entry cmd_last_pane_entry = { 41 | "last-pane", "lastp", 42 | "t:", 0, 0, 43 | CMD_TARGET_WINDOW_USAGE, 44 | 0, 45 | NULL, 46 | NULL, 47 | cmd_select_pane_exec 48 | }; 49 | 50 | void 51 | cmd_select_pane_key_binding(struct cmd *self, int key) 52 | { 53 | self->args = args_create(0); 54 | if (key == KEYC_UP) 55 | args_set(self->args, 'U', NULL); 56 | if (key == KEYC_DOWN) 57 | args_set(self->args, 'D', NULL); 58 | if (key == KEYC_LEFT) 59 | args_set(self->args, 'L', NULL); 60 | if (key == KEYC_RIGHT) 61 | args_set(self->args, 'R', NULL); 62 | if (key == 'o') 63 | args_set(self->args, 't', ":.+"); 64 | } 65 | 66 | enum cmd_retval 67 | cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx) 68 | { 69 | struct args *args = self->args; 70 | struct winlink *wl; 71 | struct window_pane *wp; 72 | 73 | if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { 74 | wl = cmd_find_window(ctx, args_get(args, 't'), NULL); 75 | if (wl == NULL) 76 | return (CMD_RETURN_ERROR); 77 | 78 | if (wl->window->last == NULL) { 79 | ctx->error(ctx, "no last pane"); 80 | return (CMD_RETURN_ERROR); 81 | } 82 | 83 | window_set_active_pane(wl->window, wl->window->last); 84 | server_status_window(wl->window); 85 | server_redraw_window_borders(wl->window); 86 | 87 | return (CMD_RETURN_NORMAL); 88 | } 89 | 90 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) 91 | return (CMD_RETURN_ERROR); 92 | 93 | if (!window_pane_visible(wp)) { 94 | ctx->error(ctx, "pane not visible"); 95 | return (CMD_RETURN_ERROR); 96 | } 97 | 98 | if (args_has(self->args, 'L')) 99 | wp = window_pane_find_left(wp); 100 | else if (args_has(self->args, 'R')) 101 | wp = window_pane_find_right(wp); 102 | else if (args_has(self->args, 'U')) 103 | wp = window_pane_find_up(wp); 104 | else if (args_has(self->args, 'D')) 105 | wp = window_pane_find_down(wp); 106 | if (wp == NULL) { 107 | ctx->error(ctx, "pane not found"); 108 | return (CMD_RETURN_ERROR); 109 | } 110 | 111 | window_set_active_pane(wl->window, wp); 112 | server_status_window(wl->window); 113 | server_redraw_window_borders(wl->window); 114 | 115 | return (CMD_RETURN_NORMAL); 116 | } 117 | -------------------------------------------------------------------------------- /cmd-send-keys.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Send keys to client. 28 | */ 29 | 30 | enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_send_keys_entry = { 33 | "send-keys", "send", 34 | "lRt:", 0, -1, 35 | "[-lR] [-t target-pane] key ...", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_send_keys_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct window_pane *wp; 47 | struct session *s; 48 | struct input_ctx *ictx; 49 | const char *str; 50 | int i, key; 51 | 52 | if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL) 53 | return (CMD_RETURN_ERROR); 54 | 55 | if (args_has(args, 'R')) { 56 | ictx = &wp->ictx; 57 | 58 | memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell); 59 | memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell); 60 | ictx->old_cx = 0; 61 | ictx->old_cy = 0; 62 | 63 | if (wp->mode == NULL) 64 | screen_write_start(&ictx->ctx, wp, &wp->base); 65 | else 66 | screen_write_start(&ictx->ctx, NULL, &wp->base); 67 | screen_write_reset(&ictx->ctx); 68 | screen_write_stop(&ictx->ctx); 69 | } 70 | 71 | for (i = 0; i < args->argc; i++) { 72 | str = args->argv[i]; 73 | 74 | if (!args_has(args, 'l') && 75 | (key = key_string_lookup_string(str)) != KEYC_NONE) { 76 | window_pane_key(wp, s, key); 77 | } else { 78 | for (; *str != '\0'; str++) 79 | window_pane_key(wp, s, *str); 80 | } 81 | } 82 | 83 | return (CMD_RETURN_NORMAL); 84 | } 85 | -------------------------------------------------------------------------------- /cmd-send-prefix.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Send prefix key as a key. 25 | */ 26 | 27 | enum cmd_retval cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_send_prefix_entry = { 30 | "send-prefix", NULL, 31 | "2t:", 0, 0, 32 | "[-2] " CMD_TARGET_PANE_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_send_prefix_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct session *s; 44 | struct window_pane *wp; 45 | int key; 46 | 47 | if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL) 48 | return (CMD_RETURN_ERROR); 49 | 50 | if (args_has(args, '2')) 51 | key = options_get_number(&s->options, "prefix2"); 52 | else 53 | key = options_get_number(&s->options, "prefix"); 54 | window_pane_key(wp, s, key); 55 | 56 | return (CMD_RETURN_NORMAL); 57 | } 58 | -------------------------------------------------------------------------------- /cmd-set-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Add or set a paste buffer. 28 | */ 29 | 30 | enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_set_buffer_entry = { 33 | "set-buffer", "setb", 34 | "b:", 1, 1, 35 | CMD_BUFFER_USAGE " data", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_set_buffer_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | u_int limit; 47 | char *pdata, *cause; 48 | size_t psize; 49 | int buffer; 50 | 51 | limit = options_get_number(&global_options, "buffer-limit"); 52 | 53 | pdata = xstrdup(args->argv[0]); 54 | psize = strlen(pdata); 55 | 56 | if (!args_has(args, 'b')) { 57 | paste_add(&global_buffers, pdata, psize, limit); 58 | return (CMD_RETURN_NORMAL); 59 | } 60 | 61 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 62 | if (cause != NULL) { 63 | ctx->error(ctx, "buffer %s", cause); 64 | free(cause); 65 | free(pdata); 66 | return (CMD_RETURN_ERROR); 67 | } 68 | 69 | if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) { 70 | ctx->error(ctx, "no buffer %d", buffer); 71 | free(pdata); 72 | return (CMD_RETURN_ERROR); 73 | } 74 | 75 | return (CMD_RETURN_NORMAL); 76 | } 77 | -------------------------------------------------------------------------------- /cmd-set-environment.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Set an environment variable. 28 | */ 29 | 30 | enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_set_environment_entry = { 33 | "set-environment", "setenv", 34 | "grt:u", 1, 2, 35 | "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_set_environment_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct session *s; 47 | struct environ *env; 48 | const char *name, *value; 49 | 50 | name = args->argv[0]; 51 | if (*name == '\0') { 52 | ctx->error(ctx, "empty variable name"); 53 | return (CMD_RETURN_ERROR); 54 | } 55 | if (strchr(name, '=') != NULL) { 56 | ctx->error(ctx, "variable name contains ="); 57 | return (CMD_RETURN_ERROR); 58 | } 59 | 60 | if (args->argc < 1) 61 | value = NULL; 62 | else 63 | value = args->argv[1]; 64 | 65 | if (args_has(self->args, 'g')) 66 | env = &global_environ; 67 | else { 68 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 69 | return (CMD_RETURN_ERROR); 70 | env = &s->environ; 71 | } 72 | 73 | if (args_has(self->args, 'u')) { 74 | if (value != NULL) { 75 | ctx->error(ctx, "can't specify a value with -u"); 76 | return (CMD_RETURN_ERROR); 77 | } 78 | environ_unset(env, name); 79 | } else if (args_has(self->args, 'r')) { 80 | if (value != NULL) { 81 | ctx->error(ctx, "can't specify a value with -r"); 82 | return (CMD_RETURN_ERROR); 83 | } 84 | environ_set(env, name, NULL); 85 | } else { 86 | if (value == NULL) { 87 | ctx->error(ctx, "no value specified"); 88 | return (CMD_RETURN_ERROR); 89 | } 90 | environ_set(env, name, value); 91 | } 92 | 93 | return (CMD_RETURN_NORMAL); 94 | } 95 | -------------------------------------------------------------------------------- /cmd-show-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Show a paste buffer. 27 | */ 28 | 29 | enum cmd_retval cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_show_buffer_entry = { 32 | "show-buffer", "showb", 33 | "b:", 0, 0, 34 | CMD_BUFFER_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_show_buffer_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct session *s; 46 | struct paste_buffer *pb; 47 | int buffer; 48 | char *in, *buf, *ptr, *cause; 49 | size_t size, len; 50 | u_int width; 51 | 52 | if ((s = cmd_find_session(ctx, NULL, 0)) == NULL) 53 | return (CMD_RETURN_ERROR); 54 | 55 | if (!args_has(args, 'b')) { 56 | if ((pb = paste_get_top(&global_buffers)) == NULL) { 57 | ctx->error(ctx, "no buffers"); 58 | return (CMD_RETURN_ERROR); 59 | } 60 | } else { 61 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 62 | if (cause != NULL) { 63 | ctx->error(ctx, "buffer %s", cause); 64 | free(cause); 65 | return (CMD_RETURN_ERROR); 66 | } 67 | 68 | pb = paste_get_index(&global_buffers, buffer); 69 | if (pb == NULL) { 70 | ctx->error(ctx, "no buffer %d", buffer); 71 | return (CMD_RETURN_ERROR); 72 | } 73 | } 74 | 75 | size = pb->size; 76 | if (size > SIZE_MAX / 4 - 1) 77 | size = SIZE_MAX / 4 - 1; 78 | in = xmalloc(size * 4 + 1); 79 | strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB); 80 | 81 | width = s->sx; 82 | if (ctx->cmdclient != NULL) 83 | width = ctx->cmdclient->tty.sx; 84 | 85 | buf = xmalloc(width + 1); 86 | len = 0; 87 | 88 | ptr = in; 89 | do { 90 | buf[len++] = *ptr++; 91 | 92 | if (len == width || buf[len - 1] == '\n') { 93 | if (buf[len - 1] == '\n') 94 | len--; 95 | buf[len] = '\0'; 96 | 97 | ctx->print(ctx, "%s", buf); 98 | len = 0; 99 | } 100 | } while (*ptr != '\0'); 101 | 102 | if (len != 0) { 103 | buf[len] = '\0'; 104 | ctx->print(ctx, "%s", buf); 105 | } 106 | free(buf); 107 | 108 | free(in); 109 | 110 | return (CMD_RETURN_NORMAL); 111 | } 112 | -------------------------------------------------------------------------------- /cmd-show-environment.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Show environment. 28 | */ 29 | 30 | enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_show_environment_entry = { 33 | "show-environment", "showenv", 34 | "gt:", 0, 1, 35 | "[-g] " CMD_TARGET_SESSION_USAGE " [name]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_show_environment_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct session *s; 47 | struct environ *env; 48 | struct environ_entry *envent; 49 | 50 | if (args_has(self->args, 'g')) 51 | env = &global_environ; 52 | else { 53 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 54 | return (CMD_RETURN_ERROR); 55 | env = &s->environ; 56 | } 57 | 58 | if (args->argc != 0) { 59 | envent = environ_find(env, args->argv[0]); 60 | if (envent == NULL) { 61 | ctx->error(ctx, "unknown variable: %s", args->argv[0]); 62 | return (CMD_RETURN_ERROR); 63 | } 64 | if (envent->value != NULL) 65 | ctx->print(ctx, "%s=%s", envent->name, envent->value); 66 | else 67 | ctx->print(ctx, "-%s", envent->name); 68 | return (CMD_RETURN_NORMAL); 69 | } 70 | 71 | RB_FOREACH(envent, environ, env) { 72 | if (envent->value != NULL) 73 | ctx->print(ctx, "%s=%s", envent->name, envent->value); 74 | else 75 | ctx->print(ctx, "-%s", envent->name); 76 | } 77 | 78 | return (CMD_RETURN_NORMAL); 79 | } 80 | -------------------------------------------------------------------------------- /cmd-show-messages.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Show client message log. 28 | */ 29 | 30 | enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_show_messages_entry = { 33 | "show-messages", "showmsgs", 34 | "t:", 0, 0, 35 | CMD_TARGET_CLIENT_USAGE, 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_show_messages_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct client *c; 47 | struct message_entry *msg; 48 | char *tim; 49 | u_int i; 50 | 51 | if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) 52 | return (CMD_RETURN_ERROR); 53 | 54 | for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { 55 | msg = &ARRAY_ITEM(&c->message_log, i); 56 | 57 | tim = ctime(&msg->msg_time); 58 | *strchr(tim, '\n') = '\0'; 59 | 60 | ctx->print(ctx, "%s %s", tim, msg->msg); 61 | } 62 | 63 | return (CMD_RETURN_NORMAL); 64 | } 65 | -------------------------------------------------------------------------------- /cmd-show-options.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Show options. 28 | */ 29 | 30 | enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_show_options_entry = { 33 | "show-options", "show", 34 | "gst:w", 0, 1, 35 | "[-gsw] [-t target-session|target-window] [option]", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_show_options_exec 40 | }; 41 | 42 | const struct cmd_entry cmd_show_window_options_entry = { 43 | "show-window-options", "showw", 44 | "gt:", 0, 1, 45 | "[-g] " CMD_TARGET_WINDOW_USAGE " [option]", 46 | 0, 47 | NULL, 48 | NULL, 49 | cmd_show_options_exec 50 | }; 51 | 52 | enum cmd_retval 53 | cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) 54 | { 55 | struct args *args = self->args; 56 | const struct options_table_entry *table, *oe; 57 | struct session *s; 58 | struct winlink *wl; 59 | struct options *oo; 60 | struct options_entry *o; 61 | const char *optval; 62 | 63 | if (args_has(self->args, 's')) { 64 | oo = &global_options; 65 | table = server_options_table; 66 | } else if (args_has(self->args, 'w') || 67 | self->entry == &cmd_show_window_options_entry) { 68 | table = window_options_table; 69 | if (args_has(self->args, 'g')) 70 | oo = &global_w_options; 71 | else { 72 | wl = cmd_find_window(ctx, args_get(args, 't'), NULL); 73 | if (wl == NULL) 74 | return (CMD_RETURN_ERROR); 75 | oo = &wl->window->options; 76 | } 77 | } else { 78 | table = session_options_table; 79 | if (args_has(self->args, 'g')) 80 | oo = &global_s_options; 81 | else { 82 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 83 | if (s == NULL) 84 | return (CMD_RETURN_ERROR); 85 | oo = &s->options; 86 | } 87 | } 88 | 89 | if (args->argc != 0) { 90 | table = oe = NULL; 91 | if (options_table_find(args->argv[0], &table, &oe) != 0) { 92 | ctx->error(ctx, "ambiguous option: %s", args->argv[0]); 93 | return (CMD_RETURN_ERROR); 94 | } 95 | if (oe == NULL) { 96 | ctx->error(ctx, "unknown option: %s", args->argv[0]); 97 | return (CMD_RETURN_ERROR); 98 | } 99 | if ((o = options_find1(oo, oe->name)) == NULL) 100 | return (CMD_RETURN_NORMAL); 101 | optval = options_table_print_entry(oe, o); 102 | ctx->print(ctx, "%s %s", oe->name, optval); 103 | } else { 104 | for (oe = table; oe->name != NULL; oe++) { 105 | if ((o = options_find1(oo, oe->name)) == NULL) 106 | continue; 107 | optval = options_table_print_entry(oe, o); 108 | ctx->print(ctx, "%s %s", oe->name, optval); 109 | } 110 | } 111 | 112 | return (CMD_RETURN_NORMAL); 113 | } 114 | -------------------------------------------------------------------------------- /cmd-source-file.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Tiago Cunha 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Sources a configuration file. 27 | */ 28 | 29 | enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_source_file_entry = { 32 | "source-file", "source", 33 | "", 1, 1, 34 | "path", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_source_file_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct causelist causes; 46 | char *cause; 47 | struct window_pane *wp; 48 | int retval; 49 | u_int i; 50 | 51 | ARRAY_INIT(&causes); 52 | 53 | retval = load_cfg(args->argv[0], ctx, &causes); 54 | if (ARRAY_EMPTY(&causes)) 55 | return (retval); 56 | 57 | if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) { 58 | wp = RB_MIN(sessions, &sessions)->curw->window->active; 59 | window_pane_set_mode(wp, &window_copy_mode); 60 | window_copy_init_for_output(wp); 61 | for (i = 0; i < ARRAY_LENGTH(&causes); i++) { 62 | cause = ARRAY_ITEM(&causes, i); 63 | window_copy_add(wp, "%s", cause); 64 | free(cause); 65 | } 66 | } else { 67 | for (i = 0; i < ARRAY_LENGTH(&causes); i++) { 68 | cause = ARRAY_ITEM(&causes, i); 69 | ctx->print(ctx, "%s", cause); 70 | free(cause); 71 | } 72 | } 73 | ARRAY_FREE(&causes); 74 | 75 | return (retval); 76 | } 77 | -------------------------------------------------------------------------------- /cmd-start-server.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Start the server and do nothing else. 25 | */ 26 | 27 | enum cmd_retval cmd_start_server_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_start_server_entry = { 30 | "start-server", "start", 31 | "", 0, 0, 32 | "", 33 | CMD_STARTSERVER, 34 | NULL, 35 | NULL, 36 | cmd_start_server_exec 37 | }; 38 | 39 | /* ARGSUSED */ 40 | enum cmd_retval 41 | cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) 42 | { 43 | return (CMD_RETURN_NORMAL); 44 | } 45 | -------------------------------------------------------------------------------- /cmd-suspend-client.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Suspend client with SIGTSTP. 28 | */ 29 | 30 | enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_suspend_client_entry = { 33 | "suspend-client", "suspendc", 34 | "t:", 0, 0, 35 | CMD_TARGET_CLIENT_USAGE, 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_suspend_client_exec 40 | }; 41 | 42 | enum cmd_retval 43 | cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct client *c; 47 | 48 | if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) 49 | return (CMD_RETURN_ERROR); 50 | 51 | tty_stop_tty(&c->tty); 52 | c->flags |= CLIENT_SUSPENDED; 53 | server_write_client(c, MSG_SUSPEND, NULL, 0); 54 | 55 | return (CMD_RETURN_NORMAL); 56 | } 57 | -------------------------------------------------------------------------------- /cmd-swap-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Swap one window with another. 27 | */ 28 | 29 | int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_swap_window_entry = { 32 | "swap-window", "swapw", 33 | "ds:t:", 0, 0, 34 | "[-d] " CMD_SRCDST_WINDOW_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_swap_window_exec 39 | }; 40 | 41 | enum cmd_retval 42 | cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | const char *target_src, *target_dst; 46 | struct session *src, *dst; 47 | struct session_group *sg_src, *sg_dst; 48 | struct winlink *wl_src, *wl_dst; 49 | struct window *w; 50 | 51 | target_src = args_get(args, 's'); 52 | if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL) 53 | return (CMD_RETURN_ERROR); 54 | target_dst = args_get(args, 't'); 55 | if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL) 56 | return (CMD_RETURN_ERROR); 57 | 58 | sg_src = session_group_find(src); 59 | sg_dst = session_group_find(dst); 60 | if (src != dst && 61 | sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) { 62 | ctx->error(ctx, "can't move window, sessions are grouped"); 63 | return (CMD_RETURN_ERROR); 64 | } 65 | 66 | if (wl_dst->window == wl_src->window) 67 | return (CMD_RETURN_NORMAL); 68 | 69 | w = wl_dst->window; 70 | wl_dst->window = wl_src->window; 71 | wl_src->window = w; 72 | 73 | if (!args_has(self->args, 'd')) { 74 | session_select(dst, wl_dst->idx); 75 | if (src != dst) 76 | session_select(src, wl_src->idx); 77 | } 78 | session_group_synchronize_from(src); 79 | server_redraw_session_group(src); 80 | if (src != dst) { 81 | session_group_synchronize_from(dst); 82 | server_redraw_session_group(dst); 83 | } 84 | recalculate_sizes(); 85 | 86 | return (CMD_RETURN_NORMAL); 87 | } 88 | -------------------------------------------------------------------------------- /cmd-switch-client.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "tmux.h" 25 | 26 | /* 27 | * Switch client to a different session. 28 | */ 29 | 30 | void cmd_switch_client_key_binding(struct cmd *, int); 31 | enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | const struct cmd_entry cmd_switch_client_entry = { 34 | "switch-client", "switchc", 35 | "lc:npt:r", 0, 0, 36 | "[-lnpr] [-c target-client] [-t target-session]", 37 | CMD_READONLY, 38 | cmd_switch_client_key_binding, 39 | NULL, 40 | cmd_switch_client_exec 41 | }; 42 | 43 | void 44 | cmd_switch_client_key_binding(struct cmd *self, int key) 45 | { 46 | self->args = args_create(0); 47 | switch (key) { 48 | case '(': 49 | args_set(self->args, 'p', NULL); 50 | break; 51 | case ')': 52 | args_set(self->args, 'n', NULL); 53 | break; 54 | case 'L': 55 | args_set(self->args, 'l', NULL); 56 | break; 57 | } 58 | } 59 | 60 | enum cmd_retval 61 | cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx) 62 | { 63 | struct args *args = self->args; 64 | struct client *c; 65 | struct session *s; 66 | 67 | if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) 68 | return (CMD_RETURN_ERROR); 69 | 70 | if (args_has(args, 'r')) { 71 | if (c->flags & CLIENT_READONLY) { 72 | c->flags &= ~CLIENT_READONLY; 73 | ctx->info(ctx, "made client writable"); 74 | } else { 75 | c->flags |= CLIENT_READONLY; 76 | ctx->info(ctx, "made client read-only"); 77 | } 78 | } 79 | 80 | s = NULL; 81 | if (args_has(args, 'n')) { 82 | if ((s = session_next_session(c->session)) == NULL) { 83 | ctx->error(ctx, "can't find next session"); 84 | return (CMD_RETURN_ERROR); 85 | } 86 | } else if (args_has(args, 'p')) { 87 | if ((s = session_previous_session(c->session)) == NULL) { 88 | ctx->error(ctx, "can't find previous session"); 89 | return (CMD_RETURN_ERROR); 90 | } 91 | } else if (args_has(args, 'l')) { 92 | if (c->last_session != NULL && session_alive(c->last_session)) 93 | s = c->last_session; 94 | if (s == NULL) { 95 | ctx->error(ctx, "can't find last session"); 96 | return (CMD_RETURN_ERROR); 97 | } 98 | } else 99 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 100 | if (s == NULL) 101 | return (CMD_RETURN_ERROR); 102 | 103 | if (c->session != NULL) 104 | c->last_session = c->session; 105 | c->session = s; 106 | session_update_activity(s); 107 | 108 | recalculate_sizes(); 109 | server_check_unattached(); 110 | server_redraw_client(c); 111 | s->curw->flags &= ~WINLINK_ALERTFLAGS; 112 | 113 | return (CMD_RETURN_NORMAL); 114 | } 115 | -------------------------------------------------------------------------------- /cmd-unbind-key.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Unbind key from command. 27 | */ 28 | 29 | enum cmd_retval cmd_unbind_key_check(struct args *); 30 | enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *); 31 | enum cmd_retval cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int); 32 | 33 | const struct cmd_entry cmd_unbind_key_entry = { 34 | "unbind-key", "unbind", 35 | "acnt:", 0, 1, 36 | "[-acn] [-t key-table] key", 37 | 0, 38 | NULL, 39 | cmd_unbind_key_check, 40 | cmd_unbind_key_exec 41 | }; 42 | 43 | enum cmd_retval 44 | cmd_unbind_key_check(struct args *args) 45 | { 46 | if (args_has(args, 'a') && args->argc != 0) 47 | return (CMD_RETURN_ERROR); 48 | if (!args_has(args, 'a') && args->argc != 1) 49 | return (CMD_RETURN_ERROR); 50 | return (CMD_RETURN_NORMAL); 51 | } 52 | 53 | enum cmd_retval 54 | cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx) 55 | { 56 | struct args *args = self->args; 57 | struct key_binding *bd; 58 | int key; 59 | 60 | if (!args_has(args, 'a')) { 61 | key = key_string_lookup_string(args->argv[0]); 62 | if (key == KEYC_NONE) { 63 | ctx->error(ctx, "unknown key: %s", args->argv[0]); 64 | return (CMD_RETURN_ERROR); 65 | } 66 | } else 67 | key = KEYC_NONE; 68 | 69 | if (args_has(args, 't')) 70 | return (cmd_unbind_key_table(self, ctx, key)); 71 | 72 | if (key == KEYC_NONE) { 73 | while (!RB_EMPTY(&key_bindings)) { 74 | bd = RB_ROOT(&key_bindings); 75 | key_bindings_remove(bd->key); 76 | } 77 | return (CMD_RETURN_NORMAL); 78 | } 79 | 80 | if (!args_has(args, 'n')) 81 | key |= KEYC_PREFIX; 82 | key_bindings_remove(key); 83 | return (CMD_RETURN_NORMAL); 84 | } 85 | 86 | enum cmd_retval 87 | cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key) 88 | { 89 | struct args *args = self->args; 90 | const char *tablename; 91 | const struct mode_key_table *mtab; 92 | struct mode_key_binding *mbind, mtmp; 93 | 94 | tablename = args_get(args, 't'); 95 | if ((mtab = mode_key_findtable(tablename)) == NULL) { 96 | ctx->error(ctx, "unknown key table: %s", tablename); 97 | return (CMD_RETURN_ERROR); 98 | } 99 | 100 | if (key == KEYC_NONE) { 101 | while (!RB_EMPTY(mtab->tree)) { 102 | mbind = RB_ROOT(mtab->tree); 103 | RB_REMOVE(mode_key_tree, mtab->tree, mbind); 104 | free(mbind); 105 | } 106 | return (CMD_RETURN_NORMAL); 107 | } 108 | 109 | mtmp.key = key; 110 | mtmp.mode = !!args_has(args, 'c'); 111 | if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) { 112 | RB_REMOVE(mode_key_tree, mtab->tree, mbind); 113 | free(mbind); 114 | } 115 | return (CMD_RETURN_NORMAL); 116 | } 117 | -------------------------------------------------------------------------------- /cmd-unlink-window.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "tmux.h" 22 | 23 | /* 24 | * Unlink a window, unless it would be destroyed by doing so (only one link). 25 | */ 26 | 27 | enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_unlink_window_entry = { 30 | "unlink-window", "unlinkw", 31 | "kt:", 0, 0, 32 | "[-k] " CMD_TARGET_WINDOW_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_unlink_window_exec 37 | }; 38 | 39 | enum cmd_retval 40 | cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct winlink *wl; 44 | struct window *w; 45 | struct session *s, *s2; 46 | struct session_group *sg; 47 | u_int references; 48 | 49 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) 50 | return (CMD_RETURN_ERROR); 51 | w = wl->window; 52 | 53 | sg = session_group_find(s); 54 | if (sg != NULL) { 55 | references = 0; 56 | TAILQ_FOREACH(s2, &sg->sessions, gentry) 57 | references++; 58 | } else 59 | references = 1; 60 | 61 | if (!args_has(self->args, 'k') && w->references == references) { 62 | ctx->error(ctx, "window is only linked to one session"); 63 | return (CMD_RETURN_ERROR); 64 | } 65 | 66 | server_unlink_window(s, wl); 67 | recalculate_sizes(); 68 | 69 | return (CMD_RETURN_NORMAL); 70 | } 71 | -------------------------------------------------------------------------------- /compat/asprintf.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2006 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #ifdef HAVE_STDINT_H 22 | #include 23 | #else 24 | #include 25 | #endif 26 | #include 27 | 28 | #include "tmux.h" 29 | 30 | int 31 | asprintf(char **ret, const char *fmt, ...) 32 | { 33 | va_list ap; 34 | int n; 35 | 36 | va_start(ap, fmt); 37 | n = vasprintf(ret, fmt, ap); 38 | va_end(ap); 39 | 40 | return (n); 41 | } 42 | 43 | int 44 | vasprintf(char **ret, const char *fmt, va_list ap) 45 | { 46 | int n; 47 | va_list ap2; 48 | 49 | va_copy(ap2, ap); 50 | 51 | if ((n = vsnprintf(NULL, 0, fmt, ap)) < 0) 52 | goto error; 53 | 54 | *ret = xmalloc(n + 1); 55 | if ((n = vsnprintf(*ret, n + 1, fmt, ap2)) < 0) { 56 | free(*ret); 57 | goto error; 58 | } 59 | 60 | return (n); 61 | 62 | error: 63 | *ret = NULL; 64 | return (-1); 65 | } 66 | -------------------------------------------------------------------------------- /compat/closefrom.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2004-2005 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "tmux.h" 20 | 21 | #ifndef HAVE_CLOSEFROM 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #ifdef HAVE_FCNTL_H 28 | # include 29 | #endif 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #ifdef HAVE_DIRENT_H 36 | # include 37 | # define NAMLEN(dirent) strlen((dirent)->d_name) 38 | #else 39 | # define dirent direct 40 | # define NAMLEN(dirent) (dirent)->d_namlen 41 | # ifdef HAVE_SYS_NDIR_H 42 | # include 43 | # endif 44 | # ifdef HAVE_SYS_DIR_H 45 | # include 46 | # endif 47 | # ifdef HAVE_NDIR_H 48 | # include 49 | # endif 50 | #endif 51 | 52 | #ifndef OPEN_MAX 53 | # define OPEN_MAX 256 54 | #endif 55 | 56 | #if 0 57 | __unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $"; 58 | #endif /* lint */ 59 | 60 | /* 61 | * Close all file descriptors greater than or equal to lowfd. 62 | */ 63 | #ifdef HAVE_FCNTL_CLOSEM 64 | void 65 | closefrom(int lowfd) 66 | { 67 | (void) fcntl(lowfd, F_CLOSEM, 0); 68 | } 69 | #else 70 | void 71 | closefrom(int lowfd) 72 | { 73 | long fd, maxfd; 74 | #if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID) 75 | char fdpath[PATH_MAX], *endp; 76 | struct dirent *dent; 77 | DIR *dirp; 78 | int len; 79 | 80 | /* Check for a /proc/$$/fd directory. */ 81 | len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); 82 | if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { 83 | while ((dent = readdir(dirp)) != NULL) { 84 | fd = strtol(dent->d_name, &endp, 10); 85 | if (dent->d_name != endp && *endp == '\0' && 86 | fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp)) 87 | (void) close((int) fd); 88 | } 89 | (void) closedir(dirp); 90 | } else 91 | #endif 92 | { 93 | /* 94 | * Fall back on sysconf() or getdtablesize(). We avoid checking 95 | * resource limits since it is possible to open a file descriptor 96 | * and then drop the rlimit such that it is below the open fd. 97 | */ 98 | #ifdef HAVE_SYSCONF 99 | maxfd = sysconf(_SC_OPEN_MAX); 100 | #else 101 | maxfd = getdtablesize(); 102 | #endif /* HAVE_SYSCONF */ 103 | if (maxfd < 0) 104 | maxfd = OPEN_MAX; 105 | 106 | for (fd = lowfd; fd < maxfd; fd++) 107 | (void) close((int) fd); 108 | } 109 | } 110 | #endif /* !HAVE_FCNTL_CLOSEM */ 111 | #endif /* HAVE_CLOSEFROM */ 112 | -------------------------------------------------------------------------------- /compat/daemon.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: daemon.c,v 1.6 2005/08/08 08:05:33 espie Exp $ */ 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "tmux.h" 37 | 38 | int 39 | daemon(int nochdir, int noclose) 40 | { 41 | int fd; 42 | 43 | switch (fork()) { 44 | case -1: 45 | return (-1); 46 | case 0: 47 | break; 48 | default: 49 | _exit(0); 50 | } 51 | 52 | if (setsid() == -1) 53 | return (-1); 54 | 55 | if (!nochdir) 56 | (void)chdir("/"); 57 | 58 | if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { 59 | (void)dup2(fd, STDIN_FILENO); 60 | (void)dup2(fd, STDOUT_FILENO); 61 | (void)dup2(fd, STDERR_FILENO); 62 | if (fd > 2) 63 | (void)close (fd); 64 | } 65 | return (0); 66 | } 67 | -------------------------------------------------------------------------------- /compat/fgetln.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $NetBSD: fgetln.c,v 1.3 2007/08/07 02:06:58 lukem Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 | * All rights reserved. 7 | * 8 | * This code is derived from software contributed to The NetBSD Foundation 9 | * by Christos Zoulas. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of The NetBSD Foundation nor the names of its 20 | * contributors may be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 24 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "tmux.h" 44 | 45 | char * 46 | fgetln(FILE *fp, size_t *len) 47 | { 48 | static char *buf = NULL; 49 | static size_t bufsiz = 0; 50 | char *ptr; 51 | 52 | 53 | if (buf == NULL) { 54 | bufsiz = BUFSIZ; 55 | if ((buf = malloc(bufsiz)) == NULL) 56 | return NULL; 57 | } 58 | 59 | if (fgets(buf, bufsiz, fp) == NULL) 60 | return NULL; 61 | 62 | *len = 0; 63 | while ((ptr = strchr(&buf[*len], '\n')) == NULL) { 64 | size_t nbufsiz = bufsiz + BUFSIZ; 65 | char *nbuf = realloc(buf, nbufsiz); 66 | 67 | if (nbuf == NULL) { 68 | int oerrno = errno; 69 | free(buf); 70 | errno = oerrno; 71 | buf = NULL; 72 | return NULL; 73 | } else 74 | buf = nbuf; 75 | 76 | *len = bufsiz; 77 | if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) 78 | return buf; 79 | 80 | bufsiz = nbufsiz; 81 | } 82 | 83 | *len = (ptr - buf) + 1; 84 | return buf; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /compat/forkpty-aix.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "tmux.h" 28 | 29 | pid_t 30 | forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws) 31 | { 32 | int slave, fd; 33 | char *path; 34 | pid_t pid; 35 | 36 | if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1) 37 | return (-1); 38 | 39 | if ((path = ttyname(*master)) == NULL) 40 | goto out; 41 | if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1) 42 | goto out; 43 | 44 | switch (pid = fork()) { 45 | case -1: 46 | goto out; 47 | case 0: 48 | close(*master); 49 | 50 | fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); 51 | if (fd >= 0) { 52 | ioctl(fd, TIOCNOTTY, NULL); 53 | close(fd); 54 | } 55 | 56 | if (setsid() < 0) 57 | fatal("setsid"); 58 | 59 | fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); 60 | if (fd >= 0) 61 | fatalx("open succeeded (failed to disconnect)"); 62 | 63 | fd = open(path, O_RDWR); 64 | if (fd < 0) 65 | fatal("open failed"); 66 | close(fd); 67 | 68 | fd = open("/dev/tty", O_WRONLY); 69 | if (fd < 0) 70 | fatal("open failed"); 71 | close(fd); 72 | 73 | if (tio != NULL && tcsetattr(slave, TCSAFLUSH, tio) == -1) 74 | fatal("tcsetattr failed"); 75 | if (ioctl(slave, TIOCSWINSZ, ws) == -1) 76 | fatal("ioctl failed"); 77 | 78 | dup2(slave, 0); 79 | dup2(slave, 1); 80 | dup2(slave, 2); 81 | if (slave > 2) 82 | close(slave); 83 | return (0); 84 | } 85 | 86 | close(slave); 87 | return (pid); 88 | 89 | out: 90 | if (*master != -1) 91 | close(*master); 92 | if (slave != -1) 93 | close(slave); 94 | return (-1); 95 | } 96 | -------------------------------------------------------------------------------- /compat/forkpty-hpux.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "tmux.h" 28 | 29 | pid_t 30 | forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) 31 | { 32 | int slave; 33 | char *path; 34 | pid_t pid; 35 | 36 | if ((*master = open("/dev/ptmx", O_RDWR|O_NOCTTY)) == -1) 37 | return (-1); 38 | if (grantpt(*master) != 0) 39 | goto out; 40 | if (unlockpt(*master) != 0) 41 | goto out; 42 | 43 | if ((path = ptsname(*master)) == NULL) 44 | goto out; 45 | if (name != NULL) 46 | strlcpy(name, path, TTY_NAME_MAX); 47 | if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1) 48 | goto out; 49 | 50 | switch (pid = fork()) { 51 | case -1: 52 | goto out; 53 | case 0: 54 | close(*master); 55 | 56 | setsid(); 57 | #ifdef TIOCSCTTY 58 | if (ioctl(slave, TIOCSCTTY, NULL) == -1) 59 | fatal("ioctl failed"); 60 | #endif 61 | 62 | if (ioctl(slave, I_PUSH, "ptem") == -1) 63 | fatal("ioctl failed"); 64 | if (ioctl(slave, I_PUSH, "ldterm") == -1) 65 | fatal("ioctl failed"); 66 | 67 | if (tio != NULL && tcsetattr(slave, TCSAFLUSH, tio) == -1) 68 | fatal("tcsetattr failed"); 69 | if (ioctl(slave, TIOCSWINSZ, ws) == -1) 70 | fatal("ioctl failed"); 71 | 72 | dup2(slave, 0); 73 | dup2(slave, 1); 74 | dup2(slave, 2); 75 | if (slave > 2) 76 | close(slave); 77 | return (0); 78 | } 79 | 80 | close(slave); 81 | return (pid); 82 | 83 | out: 84 | if (*master != -1) 85 | close(*master); 86 | if (slave != -1) 87 | close(slave); 88 | return (-1); 89 | } 90 | -------------------------------------------------------------------------------- /compat/forkpty-sunos.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "tmux.h" 28 | 29 | pid_t 30 | forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) 31 | { 32 | int slave; 33 | char *path; 34 | pid_t pid; 35 | 36 | if ((*master = open("/dev/ptmx", O_RDWR|O_NOCTTY)) == -1) 37 | return (-1); 38 | if (grantpt(*master) != 0) 39 | goto out; 40 | if (unlockpt(*master) != 0) 41 | goto out; 42 | 43 | if ((path = ptsname(*master)) == NULL) 44 | goto out; 45 | if (name != NULL) 46 | strlcpy(name, path, TTY_NAME_MAX); 47 | if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1) 48 | goto out; 49 | 50 | switch (pid = fork()) { 51 | case -1: 52 | goto out; 53 | case 0: 54 | close(*master); 55 | 56 | setsid(); 57 | #ifdef TIOCSCTTY 58 | if (ioctl(slave, TIOCSCTTY, NULL) == -1) 59 | fatal("ioctl failed"); 60 | #endif 61 | 62 | if (ioctl(slave, I_PUSH, "ptem") == -1) 63 | fatal("ioctl failed"); 64 | if (ioctl(slave, I_PUSH, "ldterm") == -1) 65 | fatal("ioctl failed"); 66 | 67 | if (tio != NULL && tcsetattr(slave, TCSAFLUSH, tio) == -1) 68 | fatal("tcsetattr failed"); 69 | if (ioctl(slave, TIOCSWINSZ, ws) == -1) 70 | fatal("ioctl failed"); 71 | 72 | dup2(slave, 0); 73 | dup2(slave, 1); 74 | dup2(slave, 2); 75 | if (slave > 2) 76 | close(slave); 77 | return (0); 78 | } 79 | 80 | close(slave); 81 | return (pid); 82 | 83 | out: 84 | if (*master != -1) 85 | close(*master); 86 | if (slave != -1) 87 | close(slave); 88 | return (-1); 89 | } 90 | -------------------------------------------------------------------------------- /compat/imsg.h: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: imsg.h,v 1.4 2010/05/26 13:56:07 nicm Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 2006, 2007 Pierre-Yves Ritschard 6 | * Copyright (c) 2006, 2007, 2008 Reyk Floeter 7 | * Copyright (c) 2003, 2004 Henning Brauer 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include "tmux.h" 23 | 24 | #define IBUF_READ_SIZE 65535 25 | #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) 26 | #define MAX_IMSGSIZE 16384 27 | 28 | struct ibuf { 29 | TAILQ_ENTRY(ibuf) entry; 30 | u_char *buf; 31 | size_t size; 32 | size_t max; 33 | size_t wpos; 34 | size_t rpos; 35 | int fd; 36 | }; 37 | 38 | struct msgbuf { 39 | TAILQ_HEAD(, ibuf) bufs; 40 | u_int32_t queued; 41 | int fd; 42 | }; 43 | 44 | struct ibuf_read { 45 | u_char buf[IBUF_READ_SIZE]; 46 | u_char *rptr; 47 | size_t wpos; 48 | }; 49 | 50 | struct imsg_fd { 51 | TAILQ_ENTRY(imsg_fd) entry; 52 | int fd; 53 | }; 54 | 55 | struct imsgbuf { 56 | TAILQ_HEAD(, imsg_fd) fds; 57 | struct ibuf_read r; 58 | struct msgbuf w; 59 | int fd; 60 | pid_t pid; 61 | }; 62 | 63 | #define IMSGF_HASFD 1 64 | 65 | struct imsg_hdr { 66 | u_int32_t type; 67 | u_int16_t len; 68 | u_int16_t flags; 69 | u_int32_t peerid; 70 | u_int32_t pid; 71 | }; 72 | 73 | struct imsg { 74 | struct imsg_hdr hdr; 75 | int fd; 76 | void *data; 77 | }; 78 | 79 | 80 | /* buffer.c */ 81 | struct ibuf *ibuf_open(size_t); 82 | struct ibuf *ibuf_dynamic(size_t, size_t); 83 | int ibuf_add(struct ibuf *, const void *, size_t); 84 | void *ibuf_reserve(struct ibuf *, size_t); 85 | void *ibuf_seek(struct ibuf *, size_t, size_t); 86 | size_t ibuf_size(struct ibuf *); 87 | size_t ibuf_left(struct ibuf *); 88 | void ibuf_close(struct msgbuf *, struct ibuf *); 89 | int ibuf_write(struct msgbuf *); 90 | void ibuf_free(struct ibuf *); 91 | void msgbuf_init(struct msgbuf *); 92 | void msgbuf_clear(struct msgbuf *); 93 | int msgbuf_write(struct msgbuf *); 94 | void msgbuf_drain(struct msgbuf *, size_t); 95 | 96 | /* imsg.c */ 97 | void imsg_init(struct imsgbuf *, int); 98 | ssize_t imsg_read(struct imsgbuf *); 99 | ssize_t imsg_get(struct imsgbuf *, struct imsg *); 100 | int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, 101 | int, void *, u_int16_t); 102 | int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, 103 | int, const struct iovec *, int); 104 | struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, 105 | u_int16_t); 106 | int imsg_add(struct ibuf *, void *, u_int16_t); 107 | void imsg_close(struct imsgbuf *, struct ibuf *); 108 | void imsg_free(struct imsg *); 109 | int imsg_flush(struct imsgbuf *); 110 | void imsg_clear(struct imsgbuf *); 111 | -------------------------------------------------------------------------------- /compat/setenv.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2010 Dagobert Michelsen 5 | * Copyright (c) 2010 Nicholas Marriott 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 16 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 17 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | int 26 | setenv(const char *name, const char *value, unused int overwrite) 27 | { 28 | char *newval; 29 | 30 | xasprintf(&newval, "%s=%s", name, value); 31 | return (putenv(newval)); 32 | } 33 | 34 | int 35 | unsetenv(const char *name) 36 | { 37 | char **envptr; 38 | int namelen; 39 | 40 | namelen = strlen(name); 41 | for (envptr = environ; *envptr != NULL; envptr++) { 42 | if (strncmp(name, *envptr, namelen) == 0 && 43 | ((*envptr)[namelen] == '=' || (*envptr)[namelen] == '\0')) 44 | break; 45 | } 46 | for (; *envptr != NULL; envptr++) 47 | *envptr = *(envptr + 1); 48 | return (0); 49 | } 50 | -------------------------------------------------------------------------------- /compat/strcasestr.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: strcasestr.c,v 1.3 2006/03/31 05:34:55 deraadt Exp $ */ 3 | /* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */ 4 | 5 | /*- 6 | * Copyright (c) 1990, 1993 7 | * The Regents of the University of California. All rights reserved. 8 | * 9 | * This code is derived from software contributed to Berkeley by 10 | * Chris Torek. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. Neither the name of the University nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | * SUCH DAMAGE. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | /* 41 | * Find the first occurrence of find in s, ignore case. 42 | */ 43 | char * 44 | strcasestr(const char *s, const char *find) 45 | { 46 | char c, sc; 47 | size_t len; 48 | 49 | if ((c = *find++) != 0) { 50 | c = (char)tolower((unsigned char)c); 51 | len = strlen(find); 52 | do { 53 | do { 54 | if ((sc = *s++) == 0) 55 | return (NULL); 56 | } while ((char)tolower((unsigned char)sc) != c); 57 | } while (strncasecmp(s, find, len) != 0); 58 | s--; 59 | } 60 | return ((char *)s); 61 | } 62 | -------------------------------------------------------------------------------- /compat/strlcat.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1998 Todd C. Miller 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Appends src to string dst of size siz (unlike strncat, siz is the 27 | * full size of dst, not space left). At most siz-1 characters 28 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). 29 | * Returns strlen(src) + MIN(siz, strlen(initial dst)). 30 | * If retval >= siz, truncation occurred. 31 | */ 32 | size_t 33 | strlcat(char *dst, const char *src, size_t siz) 34 | { 35 | char *d = dst; 36 | const char *s = src; 37 | size_t n = siz; 38 | size_t dlen; 39 | 40 | /* Find the end of dst and adjust bytes left but don't go past end */ 41 | while (n-- != 0 && *d != '\0') 42 | d++; 43 | dlen = d - dst; 44 | n = siz - dlen; 45 | 46 | if (n == 0) 47 | return(dlen + strlen(s)); 48 | while (*s != '\0') { 49 | if (n != 1) { 50 | *d++ = *s; 51 | n--; 52 | } 53 | s++; 54 | } 55 | *d = '\0'; 56 | 57 | return(dlen + (s - src)); /* count does not include NUL */ 58 | } 59 | -------------------------------------------------------------------------------- /compat/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1998 Todd C. Miller 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Copy src to string dst of size siz. At most siz-1 characters 27 | * will be copied. Always NUL terminates (unless siz == 0). 28 | * Returns strlen(src); if retval >= siz, truncation occurred. 29 | */ 30 | size_t 31 | strlcpy(char *dst, const char *src, size_t siz) 32 | { 33 | char *d = dst; 34 | const char *s = src; 35 | size_t n = siz; 36 | 37 | /* Copy as many bytes as will fit */ 38 | if (n != 0 && --n != 0) { 39 | do { 40 | if ((*d++ = *s++) == 0) 41 | break; 42 | } while (--n != 0); 43 | } 44 | 45 | /* Not enough room in dst, add NUL and traverse rest of src */ 46 | if (n == 0) { 47 | if (siz != 0) 48 | *d = '\0'; /* NUL-terminate dst */ 49 | while (*s++) 50 | ; 51 | } 52 | 53 | return(s - src - 1); /* count does not include NUL */ 54 | } 55 | -------------------------------------------------------------------------------- /compat/strsep.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: strsep.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1990, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | 36 | /* 37 | * Get next token from string *stringp, where tokens are possibly-empty 38 | * strings separated by characters from delim. 39 | * 40 | * Writes NULs into the string at *stringp to end tokens. 41 | * delim need not remain constant from call to call. 42 | * On return, *stringp points past the last NUL written (if there might 43 | * be further tokens), or is NULL (if there are definitely no more tokens). 44 | * 45 | * If *stringp is NULL, strsep returns NULL. 46 | */ 47 | char * 48 | strsep(char **stringp, const char *delim) 49 | { 50 | char *s; 51 | const char *spanp; 52 | int c, sc; 53 | char *tok; 54 | 55 | if ((s = *stringp) == NULL) 56 | return (NULL); 57 | for (tok = s;;) { 58 | c = *s++; 59 | spanp = delim; 60 | do { 61 | if ((sc = *spanp++) == c) { 62 | if (c == 0) 63 | s = NULL; 64 | else 65 | s[-1] = 0; 66 | *stringp = s; 67 | return (tok); 68 | } 69 | } while (sc != 0); 70 | } 71 | /* NOTREACHED */ 72 | } 73 | -------------------------------------------------------------------------------- /compat/strtonum.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 2004 Ted Unangst and Todd Miller 6 | * All rights reserved. 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice appear in all copies. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "tmux.h" 26 | 27 | #define INVALID 1 28 | #define TOOSMALL 2 29 | #define TOOLARGE 3 30 | 31 | long long 32 | strtonum(const char *numstr, long long minval, long long maxval, 33 | const char **errstrp) 34 | { 35 | long long ll = 0; 36 | char *ep; 37 | int error = 0; 38 | struct errval { 39 | const char *errstr; 40 | int err; 41 | } ev[4] = { 42 | { NULL, 0 }, 43 | { "invalid", EINVAL }, 44 | { "too small", ERANGE }, 45 | { "too large", ERANGE }, 46 | }; 47 | 48 | ev[0].err = errno; 49 | errno = 0; 50 | if (minval > maxval) 51 | error = INVALID; 52 | else { 53 | ll = strtoll(numstr, &ep, 10); 54 | if (numstr == ep || *ep != '\0') 55 | error = INVALID; 56 | else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) 57 | error = TOOSMALL; 58 | else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) 59 | error = TOOLARGE; 60 | } 61 | if (errstrp != NULL) 62 | *errstrp = ev[error].errstr; 63 | errno = ev[error].err; 64 | if (error) 65 | ll = 0; 66 | 67 | return (ll); 68 | } 69 | -------------------------------------------------------------------------------- /compat/vis.h: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | /* $OpenBSD: vis.h,v 1.11 2005/08/09 19:38:31 millert Exp $ */ 3 | /* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ 4 | 5 | /*- 6 | * Copyright (c) 1990 The Regents of the University of California. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#)vis.h 5.9 (Berkeley) 4/3/91 34 | */ 35 | 36 | #ifndef _VIS_H_ 37 | #define _VIS_H_ 38 | 39 | /* 40 | * to select alternate encoding format 41 | */ 42 | #define VIS_OCTAL 0x01 /* use octal \ddd format */ 43 | #define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ 44 | 45 | /* 46 | * to alter set of characters encoded (default is to encode all 47 | * non-graphic except space, tab, and newline). 48 | */ 49 | #define VIS_SP 0x04 /* also encode space */ 50 | #define VIS_TAB 0x08 /* also encode tab */ 51 | #define VIS_NL 0x10 /* also encode newline */ 52 | #define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) 53 | #define VIS_SAFE 0x20 /* only encode "unsafe" characters */ 54 | 55 | /* 56 | * other 57 | */ 58 | #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ 59 | #define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */ 60 | 61 | /* 62 | * unvis return codes 63 | */ 64 | #define UNVIS_VALID 1 /* character valid */ 65 | #define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ 66 | #define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ 67 | #define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ 68 | #define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ 69 | 70 | /* 71 | * unvis flags 72 | */ 73 | #define UNVIS_END 1 /* no more characters */ 74 | 75 | char *vis(char *, int, int, int); 76 | int strvis(char *, const char *, int); 77 | int strnvis(char *, const char *, size_t, int); 78 | int strvisx(char *, const char *, size_t, int); 79 | int strunvis(char *, const char *); 80 | int unvis(char *, char, int *, int); 81 | ssize_t strnunvis(char *, const char *, size_t); 82 | 83 | #endif /* !_VIS_H_ */ 84 | -------------------------------------------------------------------------------- /control.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2012 Nicholas Marriott 5 | * Copyright (c) 2012 George Nachman 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 16 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 17 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "tmux.h" 27 | 28 | void printflike2 control_msg_error(struct cmd_ctx *, const char *, ...); 29 | void printflike2 control_msg_print(struct cmd_ctx *, const char *, ...); 30 | void printflike2 control_msg_info(struct cmd_ctx *, const char *, ...); 31 | 32 | /* Command error callback. */ 33 | void printflike2 34 | control_msg_error(struct cmd_ctx *ctx, const char *fmt, ...) 35 | { 36 | struct client *c = ctx->curclient; 37 | va_list ap; 38 | 39 | va_start(ap, fmt); 40 | evbuffer_add_vprintf(c->stdout_data, fmt, ap); 41 | va_end(ap); 42 | 43 | evbuffer_add(c->stdout_data, "\n", 1); 44 | server_push_stdout(c); 45 | } 46 | 47 | /* Command print callback. */ 48 | void printflike2 49 | control_msg_print(struct cmd_ctx *ctx, const char *fmt, ...) 50 | { 51 | struct client *c = ctx->curclient; 52 | va_list ap; 53 | 54 | va_start(ap, fmt); 55 | evbuffer_add_vprintf(c->stdout_data, fmt, ap); 56 | va_end(ap); 57 | 58 | evbuffer_add(c->stdout_data, "\n", 1); 59 | server_push_stdout(c); 60 | } 61 | 62 | /* Command info callback. */ 63 | void printflike2 64 | control_msg_info(unused struct cmd_ctx *ctx, unused const char *fmt, ...) 65 | { 66 | } 67 | 68 | /* Write a line. */ 69 | void printflike2 70 | control_write(struct client *c, const char *fmt, ...) 71 | { 72 | va_list ap; 73 | 74 | va_start(ap, fmt); 75 | evbuffer_add_vprintf(c->stdout_data, fmt, ap); 76 | va_end(ap); 77 | 78 | evbuffer_add(c->stdout_data, "\n", 1); 79 | server_push_stdout(c); 80 | } 81 | 82 | /* Control input callback. Read lines and fire commands. */ 83 | void 84 | control_callback(struct client *c, int closed, unused void *data) 85 | { 86 | char *line, *cause; 87 | struct cmd_ctx ctx; 88 | struct cmd_list *cmdlist; 89 | 90 | if (closed) 91 | c->flags |= CLIENT_EXIT; 92 | 93 | for (;;) { 94 | line = evbuffer_readln(c->stdin_data, NULL, EVBUFFER_EOL_LF); 95 | if (line == NULL) 96 | break; 97 | if (*line == '\0') { /* empty line exit */ 98 | c->flags |= CLIENT_EXIT; 99 | break; 100 | } 101 | 102 | ctx.msgdata = NULL; 103 | ctx.cmdclient = NULL; 104 | ctx.curclient = c; 105 | 106 | ctx.error = control_msg_error; 107 | ctx.print = control_msg_print; 108 | ctx.info = control_msg_info; 109 | 110 | if (cmd_string_parse(line, &cmdlist, &cause) != 0) { 111 | control_write(c, "%%error in line \"%s\": %s", line, 112 | cause); 113 | free(cause); 114 | } else { 115 | cmd_list_exec(cmdlist, &ctx); 116 | cmd_list_free(cmdlist); 117 | } 118 | 119 | free(line); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /examples/bash_completion_tmux.sh: -------------------------------------------------------------------------------- 1 | # START tmux completion 2 | # This file is in the public domain 3 | # See: http://www.debian-administration.org/articles/317 for how to write more. 4 | # Usage: Put "source bash_completion_tmux.sh" into your .bashrc 5 | _tmux() 6 | { 7 | local cur prev opts 8 | COMPREPLY=() 9 | cur="${COMP_WORDS[COMP_CWORD]}" 10 | prev="${COMP_WORDS[COMP_CWORD-1]}" 11 | 12 | opts=" \ 13 | attach-session \ 14 | bind-key \ 15 | break-pane \ 16 | capture-pane \ 17 | choose-client \ 18 | choose-session \ 19 | choose-window \ 20 | clear-history \ 21 | clock-mode \ 22 | command-prompt \ 23 | confirm-before \ 24 | copy-buffer \ 25 | copy-mode \ 26 | delete-buffer \ 27 | detach-client \ 28 | display-message \ 29 | display-panes \ 30 | down-pane \ 31 | find-window \ 32 | has-session \ 33 | if-shell \ 34 | join-pane \ 35 | kill-pane \ 36 | kill-server \ 37 | kill-session \ 38 | kill-window \ 39 | last-window \ 40 | link-window \ 41 | list-buffers \ 42 | list-clients \ 43 | list-commands \ 44 | list-keys \ 45 | list-panes \ 46 | list-sessions \ 47 | list-windows \ 48 | load-buffer \ 49 | lock-client \ 50 | lock-server \ 51 | lock-session \ 52 | move-window \ 53 | new-session \ 54 | new-window \ 55 | next-layout \ 56 | next-window \ 57 | paste-buffer \ 58 | pipe-pane \ 59 | previous-layout \ 60 | previous-window \ 61 | refresh-client \ 62 | rename-session \ 63 | rename-window \ 64 | resize-pane \ 65 | respawn-window \ 66 | rotate-window \ 67 | run-shell \ 68 | save-buffer \ 69 | select-layout \ 70 | select-pane \ 71 | select-prompt \ 72 | select-window \ 73 | send-keys \ 74 | send-prefix \ 75 | server-info \ 76 | set-buffer \ 77 | set-environment \ 78 | set-option \ 79 | set-window-option \ 80 | show-buffer \ 81 | show-environment \ 82 | show-messages \ 83 | show-options \ 84 | show-window-options \ 85 | source-file \ 86 | split-window \ 87 | start-server \ 88 | suspend-client \ 89 | swap-pane \ 90 | swap-window \ 91 | switch-client \ 92 | unbind-key \ 93 | unlink-window \ 94 | up-pane" 95 | 96 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) 97 | return 0 98 | 99 | } 100 | complete -F _tmux tmux 101 | 102 | # END tmux completion 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /examples/h-boetes.conf: -------------------------------------------------------------------------------- 1 | # $Id: h-boetes.conf,v 1.2 2009-10-25 21:45:26 nicm Exp $ 2 | # 3 | # From Han Boetes. 4 | 5 | set -g default-command zsh 6 | set -g status-right "#(uptime|awk '{print $11}') #(date)" 7 | 8 | # Statusbar properties. 9 | set -g display-time 3000 10 | set -g status-bg black 11 | set -g status-fg cyan 12 | set-window-option -g window-status-current-attr bright,reverse 13 | set-window-option -g window-status-current-bg cyan 14 | set-window-option -g window-status-current-fg black 15 | 16 | # Use c-t instead of c-b as the prefix 17 | unbind C-b 18 | set -g prefix C-t 19 | bind C-t send-prefix 20 | bind t send-prefix 21 | 22 | # Bind function keys. 23 | bind -n F1 select-window -t 1 24 | bind -n F2 select-window -t 2 25 | bind -n F3 select-window -t 3 26 | bind -n F4 select-window -t 4 27 | bind -n F5 select-window -t 5 28 | bind -n F6 select-window -t 6 29 | bind -n F7 select-window -t 7 30 | bind -n F8 select-window -t 8 31 | 32 | # All new windows started at startup. 33 | new emacs 34 | neww irssi 35 | neww mutt 36 | neww 37 | neww 38 | neww 39 | neww 40 | neww 41 | 42 | select-window -t 1 43 | -------------------------------------------------------------------------------- /examples/n-marriott.conf: -------------------------------------------------------------------------------- 1 | # $Id: n-marriott.conf,v 1.11 2009-11-24 19:03:59 nicm Exp $ 2 | # 3 | # By Nicholas Marriott. Public domain. 4 | 5 | # Default global options. 6 | set -g status-bg green 7 | set -g status-right "%H:%M" # %d-%b-%y 8 | set -g bell-action none 9 | set -g lock-after-time 1800 10 | 11 | # Default global window options. 12 | setw -g remain-on-exit on 13 | setw -g window-status-current-attr "underscore" 14 | #setw -g xterm-keys on 15 | 16 | # Prefix key. 17 | set -g prefix C-a 18 | unbind C-b 19 | bind C-a send-prefix 20 | 21 | # Keys to switch session. 22 | bind Q switchc -t0 23 | bind W switchc -t1 24 | bind E switchc -t2 25 | 26 | # Other key bindings. 27 | bind F1 selectw -t:10 28 | bind F2 selectw -t:11 29 | bind F3 selectw -t:12 30 | bind F4 selectw -t:13 31 | bind F5 selectw -t:14 32 | bind F6 selectw -t:15 33 | bind F7 selectw -t:16 34 | bind F8 selectw -t:17 35 | bind F9 selectw -t:18 36 | bind F10 selectw -t:19 37 | bind F11 selectw -t:20 38 | bind F12 selectw -t:21 39 | 40 | bind m setw monitor-activity 41 | 42 | bind y setw force-width 81 43 | bind u setw force-width 0 44 | 45 | bind -n F1 run-shell 'mpc toggle >/dev/null 2>&1' 46 | bind -n F2 run-shell 'mpc' 47 | bind -n F3 run-shell 'mpc prev >/dev/null 2>&1' 48 | bind -n F4 run-shell 'mpc next >/dev/null 2>&1' 49 | bind -n F5 run-shell 'mpc volume -5 >/dev/null 2>&1' 50 | bind -n F6 run-shell 'mpc volume +5 >/dev/null 2>&1' 51 | 52 | # Hide and show window name from status line 53 | bind '-' setw window-status-format '#I'\; setw window-status-current-format '#I' 54 | bind '+' setw window-status-format '#I:#W#F'\; setw window-status-current-format '#I:#W#F' 55 | 56 | # First session. 57 | new -d -s0 -nirssi 'exec ssh -t natalya exec sh ~/bin/tmux-start' 58 | setw -t0:0 monitor-activity on 59 | setw -t0:0 aggressive-resize on 60 | set -t0 status-bg green 61 | neww -d -ntodo 'exec emacs ~/TODO' 62 | setw -t0:1 aggressive-resize on 63 | neww -d -ntodo2 'exec emacs ~/TODO2' 64 | setw -t0:2 aggressive-resize on 65 | neww -d -nncmpc 'exec ncmpc -f ~/.ncmpc.conf' 66 | setw -t0:3 aggressive-resize on 67 | neww -d -nmutt 'exec mutt' 68 | setw -t0:4 aggressive-resize on 69 | neww -d 70 | neww -d 71 | neww -d 72 | neww -d 73 | neww -d 74 | neww -d 75 | neww -d 76 | neww -d 77 | neww -d 78 | neww -d 79 | neww -d 80 | neww -d 81 | 82 | # Second session. 83 | new -d -s1 84 | set -t1 status-bg cyan 85 | linkw -dk -t0 -s0:0 86 | linkw -dk -t1 -s0:1 87 | linkw -dk -t2 -s0:2 88 | linkw -dk -t3 -s0:3 89 | linkw -dk -t4 -s0:4 90 | neww -d 91 | neww -d 92 | neww -d 93 | neww -d 94 | neww -d 95 | neww -d 96 | 97 | # Third session. 98 | new -d -s2 99 | set -t2 status-bg yellow 100 | linkw -dk -t0 -s0:0 101 | linkw -dk -t1 -s0:1 102 | linkw -dk -t2 -s0:2 103 | linkw -dk -t3 -s0:3 104 | linkw -dk -t4 -s0:4 105 | neww -d 106 | neww -d 107 | neww -d 108 | neww -d 109 | neww -d 110 | neww -d 111 | -------------------------------------------------------------------------------- /examples/screen-keys.conf: -------------------------------------------------------------------------------- 1 | # $Id: screen-keys.conf,v 1.7 2010-07-31 11:39:13 nicm Exp $ 2 | # 3 | # By Nicholas Marriott. Public domain. 4 | # 5 | # This configuration file binds many of the common GNU screen key bindings to 6 | # appropriate tmux key bindings. Note that for some key bindings there is no 7 | # tmux analogue and also that this set omits binding some commands available in 8 | # tmux but not in screen. 9 | # 10 | # Note this is only a selection of key bindings and they are in addition to the 11 | # normal tmux key bindings. This is intended as an example not as to be used 12 | # as-is. 13 | 14 | # Set the prefix to ^A. 15 | unbind C-b 16 | set -g prefix ^A 17 | bind a send-prefix 18 | 19 | # Bind appropriate commands similar to screen. 20 | # lockscreen ^X x 21 | unbind ^X 22 | bind ^X lock-server 23 | unbind x 24 | bind x lock-server 25 | 26 | # screen ^C c 27 | unbind ^C 28 | bind ^C new-window 29 | unbind c 30 | bind c new-window 31 | 32 | # detach ^D d 33 | unbind ^D 34 | bind ^D detach 35 | 36 | # displays * 37 | unbind * 38 | bind * list-clients 39 | 40 | # next ^@ ^N sp n 41 | unbind ^@ 42 | bind ^@ next-window 43 | unbind ^N 44 | bind ^N next-window 45 | unbind " " 46 | bind " " next-window 47 | unbind n 48 | bind n next-window 49 | 50 | # title A 51 | unbind A 52 | bind A command-prompt "rename-window %%" 53 | 54 | # other ^A 55 | unbind ^A 56 | bind ^A last-window 57 | 58 | # prev ^H ^P p ^? 59 | unbind ^H 60 | bind ^H previous-window 61 | unbind ^P 62 | bind ^P previous-window 63 | unbind p 64 | bind p previous-window 65 | unbind BSpace 66 | bind BSpace previous-window 67 | 68 | # windows ^W w 69 | unbind ^W 70 | bind ^W list-windows 71 | unbind w 72 | bind w list-windows 73 | 74 | # quit \ 75 | unbind '\' 76 | bind '\' confirm-before "kill-server" 77 | 78 | # kill K k 79 | unbind K 80 | bind K confirm-before "kill-window" 81 | unbind k 82 | bind k confirm-before "kill-window" 83 | 84 | # redisplay ^L l 85 | unbind ^L 86 | bind ^L refresh-client 87 | unbind l 88 | bind l refresh-client 89 | 90 | # split -v | 91 | unbind | 92 | bind | split-window 93 | 94 | # :kB: focus up 95 | unbind Tab 96 | bind Tab select-pane -t:.+ 97 | unbind BTab 98 | bind BTab select-pane -t:.- 99 | 100 | # " windowlist -b 101 | unbind '"' 102 | bind '"' choose-window 103 | -------------------------------------------------------------------------------- /examples/t-williams.conf: -------------------------------------------------------------------------------- 1 | # $Id: t-williams.conf,v 1.1 2009-11-02 18:59:28 nicm Exp $ 2 | # 3 | # ~/.tmux.conf - tmux terminal multiplexer config 4 | # Thayer Williams (http://cinderwick.ca) 5 | # "Feel free to do whatever you like with it." 6 | 7 | # I typically start tmux from ~/.xinitrc with the following: 8 | # 9 | # urxvt -e bash -c "tmux attach -d -t mysession" & 10 | # 11 | # and recall it any time thereafter with xbindkeys (Mod4+s): 12 | # 13 | # "urxvt -e bash -c 'tmux attach -d -t mysession'" 14 | # m:0x50 + c:39 15 | 16 | 17 | # set prefix key to ctrl+a until I have time to adapt 18 | unbind C-b 19 | set -g prefix C-a 20 | 21 | # send the prefix to client inside window (ala nested sessions) 22 | bind-key a send-prefix 23 | 24 | # toggle last window like screen 25 | bind-key C-a last-window 26 | 27 | # confirm before killing a window or the server 28 | bind-key k confirm kill-window 29 | bind-key K confirm kill-server 30 | 31 | # toggle statusbar 32 | bind-key b set-option status 33 | 34 | # ctrl+left/right cycles thru windows 35 | bind-key -n C-right next 36 | bind-key -n C-left prev 37 | 38 | # open a man page in new window 39 | bind / command-prompt "split-window 'exec man %%'" 40 | 41 | # quick view of processes 42 | bind '~' split-window "exec htop" 43 | 44 | # scrollback buffer n lines 45 | set -g history-limit 5000 46 | 47 | # listen for activity on all windows 48 | set -g bell-action any 49 | 50 | # on-screen time for display-panes in ms 51 | set -g display-panes-time 2000 52 | 53 | # start window indexing at one instead of zero 54 | set -g base-index 1 55 | 56 | # enable wm window titles 57 | set -g set-titles on 58 | 59 | # wm window title string (uses statusbar variables) 60 | set -g set-titles-string "tmux.#I.#W" 61 | 62 | # session initialization 63 | new -s mysession mutt 64 | neww -t 2 65 | neww -d -t 3 66 | neww -d -t 5 mocp 67 | neww -d -t 6 rtorrent 68 | selectw -t 1 69 | 70 | # statusbar -------------------------------------------------------------- 71 | 72 | set -g display-time 2000 73 | 74 | # default statusbar colors 75 | set -g status-fg white 76 | set -g status-bg default 77 | set -g status-attr default 78 | 79 | # default window title colors 80 | set-window-option -g window-status-fg cyan 81 | set-window-option -g window-status-bg default 82 | set-window-option -g window-status-attr dim 83 | 84 | # active window title colors 85 | set-window-option -g window-status-current-fg white 86 | set-window-option -g window-status-current-bg default 87 | set-window-option -g window-status-current-attr bright 88 | 89 | # command/message line colors 90 | set -g message-fg white 91 | set -g message-bg black 92 | set -g message-attr bright 93 | 94 | # center align the window list 95 | set -g status-justify centre 96 | 97 | # show some useful stats but only when tmux is started 98 | # outside of Xorg, otherwise dwm statusbar shows these already 99 | set -g status-right "" 100 | set -g status-left "" 101 | if '[ -z "$DISPLAY" ]' 'set -g status-left "[#[fg=green] #H #[default]]"' 102 | if '[ -z "$DISPLAY" ]' 'set -g status-right "[ #[fg=magenta]#(cat /proc/loadavg | cut -d \" \" -f 1,2,3)#[default] ][ #[fg=cyan,bright]%a %Y-%m-%d %H:%M #[default]]"' 103 | if '[ -z "$DISPLAY" ]' 'set -g status-right-length 50' 104 | 105 | -------------------------------------------------------------------------------- /examples/tmux-zoom.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2012 Juan Ignacio Pumarino, jipumarino@gmail.com 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | # Instructions 25 | # ------------ 26 | # 27 | # 1. Install this script and give it execute permission somewhere in your PATH. 28 | # For example: 29 | # 30 | # $ mkdir -p ~/bin 31 | # $ wget https://raw.github.com/jipumarino/tmux-zoom/master/tmux-zoom.sh -O ~/bin/tmux-zoom.sh 32 | # $ chmod +x ~/bin/tmux-zoom.sh 33 | # 34 | # 2. Add a shortcut in your ~/.tmux.conf file: 35 | # 36 | # bind C-k run "tmux-zoom.sh" 37 | # 38 | # 3. When using this shortcut, the current tmux pane will open in a new window by itself. 39 | # Running it again in the zoomed window will return it to its original pane. You can have 40 | # as many zoomed windows as you want. 41 | 42 | current=$(tmux display-message -p '#W-#I-#P') 43 | list=$(tmux list-window) 44 | 45 | [[ "$current" =~ ^(.*)-([0-9]+)-([0-9]+) ]] 46 | current_window=${BASH_REMATCH[1]} 47 | current_pane=${BASH_REMATCH[2]}-${BASH_REMATCH[3]} 48 | new_zoom_window=ZOOM-$current_pane 49 | 50 | if [[ $current_window =~ ZOOM-([0-9]+)-([0-9+]) ]]; then 51 | old_zoom_window=ZOOM-${BASH_REMATCH[1]}-${BASH_REMATCH[2]} 52 | tmux select-window -t ${BASH_REMATCH[1]} \; select-pane -t ${BASH_REMATCH[2]} \; swap-pane -s $old_zoom_window.1 \; kill-window -t $old_zoom_window 53 | elif [[ $list =~ $new_zoom_window ]]; then 54 | tmux select-window -t $new_zoom_window 55 | else 56 | tmux new-window -d -n $new_zoom_window \; swap-pane -s $new_zoom_window.1 \; select-window -t $new_zoom_window 57 | fi 58 | -------------------------------------------------------------------------------- /examples/tmux_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # By Victor Orlikowski. Public domain. 4 | # 5 | # This script maintains snapshots of each pane's 6 | # history buffer, for each tmux session you are running. 7 | # 8 | # It is intended to be run by cron, on whatever interval works 9 | # for you. 10 | 11 | # Maximum number of snapshots to keep. 12 | max_backups=12 13 | # Names of sessions you may wish to exclude from snapshotting, 14 | # space separated. 15 | ignore_sessions="" 16 | # The directory into which you want your snapshots placed. 17 | # The default is probably "good enough." 18 | backup_dir=~/.tmux_backup/snapshot 19 | 20 | ######################################################################## 21 | 22 | # Rotate previous backups. 23 | i=${max_backups} 24 | while [[ ${i} != 0 ]] ; do 25 | if [ -d ${backup_dir}.${i} ] ; then 26 | if [[ ${i} = ${max_backups} ]] ; then 27 | rm -r ${backup_dir}.${i} 28 | else 29 | mv ${backup_dir}.${i} ${backup_dir}.$((${i}+1)) 30 | fi 31 | fi 32 | i=$((${i}-1)) 33 | done 34 | 35 | if [ -d ${backup_dir} ] ; then 36 | mv ${backup_dir} ${backup_dir}.1 37 | fi 38 | 39 | ## Dump hardcopy from all windows in all available tmux sessions. 40 | unset TMUX 41 | for session in $(tmux list-sessions | cut -d' ' -f1 | sed -e 's/:$//') ; do 42 | for ignore_session in ${ignore_sessions} ; do 43 | if [ ${session} = ${ignore_session} ] ; then 44 | continue 2 45 | fi 46 | done 47 | 48 | # Session name can contain the colon character (":"). 49 | # This can screw up addressing of windows within tmux, since 50 | # target windows are specified as target-session:target-window. 51 | # 52 | # We use uuidgen to create a "safe" temporary session name, 53 | # which we then use to create a "detached" session that "links" 54 | # to the "real" session that we want to back up. 55 | tmpsession=$(uuidgen) 56 | tmux new-session -d -s "$tmpsession" -t "$session" 57 | HISTSIZE=$(tmux show-options -g -t "$tmpsession" | grep "history-limit" | awk '{print $2}') 58 | for win in $(tmux list-windows -t "$tmpsession" | grep -v "^\s" | cut -d' ' -f1 | sed -e 's/:$//'); do 59 | session_dir=$(echo "$session" | sed -e 's/ /_/g' | sed -e 's%/%|%g') 60 | win_spec="$tmpsession":"$win" 61 | 62 | if [ ! -d ${backup_dir}/${session_dir}/${win} ] ; then 63 | mkdir -p ${backup_dir}/${session_dir}/${win} 64 | fi 65 | 66 | for pane in $(tmux list-panes -t "$win_spec" | cut -d' ' -f1 | sed -e 's/:$//'); do 67 | pane_path=${backup_dir}/${session_dir}/${win}/${pane} 68 | pane_spec="$win_spec"."$pane" 69 | 70 | tmux capture-pane -t "$pane_spec" -S -${HISTSIZE} 71 | tmux save-buffer ${pane_path} 72 | 73 | if [ ! -s ${pane_path} ] ; then 74 | sleep 1 75 | rm ${pane_path} 76 | fi 77 | done 78 | done 79 | tmux kill-session -t "$tmpsession" 80 | 81 | done 82 | -------------------------------------------------------------------------------- /examples/vim-keys.conf: -------------------------------------------------------------------------------- 1 | # $Id: vim-keys.conf,v 1.2 2010-09-18 09:36:15 nicm Exp $ 2 | # 3 | # vim-keys.conf, v1.2 2010/09/12 4 | # 5 | # By Daniel Thau. Public domain. 6 | # 7 | # This configuration file binds many vi- and vim-like bindings to the 8 | # appropriate tmux key bindings. Note that for many key bindings there is no 9 | # tmux analogue. This is intended for tmux 1.3, which handles pane selection 10 | # differently from the previous versions 11 | 12 | # split windows like vim 13 | # vim's definition of a horizontal/vertical split is reversed from tmux's 14 | bind s split-window -v 15 | bind v split-window -h 16 | 17 | # move around panes with hjkl, as one would in vim after pressing ctrl-w 18 | bind h select-pane -L 19 | bind j select-pane -D 20 | bind k select-pane -U 21 | bind l select-pane -R 22 | 23 | # resize panes like vim 24 | # feel free to change the "1" to however many lines you want to resize by, only 25 | # one at a time can be slow 26 | bind < resize-pane -L 1 27 | bind > resize-pane -R 1 28 | bind - resize-pane -D 1 29 | bind + resize-pane -U 1 30 | 31 | # bind : to command-prompt like vim 32 | # this is the default in tmux already 33 | bind : command-prompt 34 | 35 | # vi-style controls for copy mode 36 | setw -g mode-keys vi 37 | -------------------------------------------------------------------------------- /grid-utf8.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Grid UTF-8 utility functions. 27 | */ 28 | 29 | /* Calculate UTF-8 grid cell size. Data is terminated by 0xff. */ 30 | size_t 31 | grid_utf8_size(const struct grid_utf8 *gu) 32 | { 33 | size_t size; 34 | 35 | for (size = 0; size < sizeof gu->data; size++) { 36 | if (gu->data[size] == 0xff) 37 | break; 38 | } 39 | return (size); 40 | } 41 | 42 | /* Copy UTF-8 out into a buffer. */ 43 | size_t 44 | grid_utf8_copy(const struct grid_utf8 *gu, char *buf, size_t len) 45 | { 46 | size_t size; 47 | 48 | size = grid_utf8_size(gu); 49 | if (size > len) 50 | fatalx("UTF-8 copy overflow"); 51 | memcpy(buf, gu->data, size); 52 | return (size); 53 | } 54 | 55 | /* Set UTF-8 grid data from input UTF-8. */ 56 | void 57 | grid_utf8_set(struct grid_utf8 *gu, const struct utf8_data *utf8data) 58 | { 59 | if (utf8data->size == 0) 60 | fatalx("UTF-8 data empty"); 61 | if (utf8data->size > sizeof gu->data) 62 | fatalx("UTF-8 data too long"); 63 | memcpy(gu->data, utf8data->data, utf8data->size); 64 | if (utf8data->size != sizeof gu->data) 65 | gu->data[utf8data->size] = 0xff; 66 | gu->width = utf8data->width; 67 | } 68 | 69 | /* Append UTF-8 character onto the cell data (for combined characters). */ 70 | int 71 | grid_utf8_append(struct grid_utf8 *gu, const struct utf8_data *utf8data) 72 | { 73 | size_t old_size; 74 | 75 | old_size = grid_utf8_size(gu); 76 | if (old_size + utf8data->size > sizeof gu->data) 77 | return (-1); 78 | memcpy(gu->data + old_size, utf8data->data, utf8data->size); 79 | if (old_size + utf8data->size != sizeof gu->data) 80 | gu->data[old_size + utf8data->size] = 0xff; 81 | return (0); 82 | } 83 | 84 | /* Compare two UTF-8 cells. */ 85 | int 86 | grid_utf8_compare(const struct grid_utf8 *gu1, const struct grid_utf8 *gu2) 87 | { 88 | size_t size; 89 | 90 | size = grid_utf8_size(gu1); 91 | if (size != grid_utf8_size(gu2)) 92 | return (0); 93 | if (memcmp(gu1->data, gu2->data, size) != 0) 94 | return (0); 95 | return (1); 96 | } 97 | -------------------------------------------------------------------------------- /osdep-aix.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2011 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | char * 26 | osdep_get_name(unused int fd, unused char *tty) 27 | { 28 | return (NULL); 29 | } 30 | 31 | char * 32 | osdep_get_cwd(pid_t pid) 33 | { 34 | return (NULL); 35 | } 36 | 37 | struct event_base * 38 | osdep_event_init(void) 39 | { 40 | return (event_init()); 41 | } 42 | -------------------------------------------------------------------------------- /osdep-darwin.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Joshua Elsasser 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | char *osdep_get_name(int, char *); 29 | char *osdep_get_cwd(pid_t); 30 | struct event_base *osdep_event_init(void); 31 | 32 | #define unused __attribute__ ((unused)) 33 | 34 | char * 35 | osdep_get_name(int fd, unused char *tty) 36 | { 37 | int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 }; 38 | size_t size; 39 | struct kinfo_proc kp; 40 | 41 | if ((mib[3] = tcgetpgrp(fd)) == -1) 42 | return (NULL); 43 | 44 | size = sizeof kp; 45 | if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1) 46 | return (NULL); 47 | if (*kp.kp_proc.p_comm == '\0') 48 | return (NULL); 49 | 50 | return (strdup(kp.kp_proc.p_comm)); 51 | } 52 | 53 | char * 54 | osdep_get_cwd(pid_t pid) 55 | { 56 | static char wd[PATH_MAX]; 57 | struct proc_vnodepathinfo pathinfo; 58 | int ret; 59 | 60 | ret = proc_pidinfo( 61 | pid, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); 62 | if (ret == sizeof pathinfo) { 63 | strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd); 64 | return (wd); 65 | } 66 | return (NULL); 67 | } 68 | 69 | struct event_base * 70 | osdep_event_init(void) 71 | { 72 | /* 73 | * On OS X, kqueue and poll are both completely broken and don't 74 | * work on anything except socket file descriptors (yes, really). 75 | */ 76 | setenv("EVENT_NOKQUEUE", "1", 1); 77 | setenv("EVENT_NOPOLL", "1", 1); 78 | return (event_init()); 79 | } 80 | -------------------------------------------------------------------------------- /osdep-dragonfly.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); 33 | char *osdep_get_name(int, char *); 34 | char *osdep_get_cwd(pid_t); 35 | struct event_base *osdep_event_init(void); 36 | 37 | #ifndef nitems 38 | #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 39 | #endif 40 | 41 | #define is_runnable(p) \ 42 | ((p)->kp_stat == SACTIVE || (p)->kp_stat == SIDL) 43 | #define is_stopped(p) \ 44 | ((p)->kp_stat == SSTOP || (p)->kp_stat == SZOMB) 45 | 46 | struct kinfo_proc * 47 | cmp_procs(struct kinfo_proc *p1, struct kinfo_proc *p2) 48 | { 49 | if (is_runnable(p1) && !is_runnable(p2)) 50 | return (p1); 51 | if (!is_runnable(p1) && is_runnable(p2)) 52 | return (p2); 53 | 54 | if (is_stopped(p1) && !is_stopped(p2)) 55 | return (p1); 56 | if (!is_stopped(p1) && is_stopped(p2)) 57 | return (p2); 58 | 59 | if (strcmp(p1->kp_comm, p2->kp_comm) < 0) 60 | return (p1); 61 | if (strcmp(p1->kp_comm, p2->kp_comm) > 0) 62 | return (p2); 63 | 64 | if (p1->kp_pid > p2->kp_pid) 65 | return (p1); 66 | return (p2); 67 | } 68 | 69 | char * 70 | osdep_get_name(int fd, char *tty) 71 | { 72 | int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 }; 73 | struct stat sb; 74 | size_t len; 75 | struct kinfo_proc *buf, *newbuf, *bestp; 76 | u_int i; 77 | char *name; 78 | 79 | buf = NULL; 80 | 81 | if (stat(tty, &sb) == -1) 82 | return (NULL); 83 | if ((mib[3] = tcgetpgrp(fd)) == -1) 84 | return (NULL); 85 | 86 | retry: 87 | if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) == -1) 88 | return (NULL); 89 | len = (len * 5) / 4; 90 | 91 | if ((newbuf = realloc(buf, len)) == NULL) 92 | goto error; 93 | buf = newbuf; 94 | 95 | if (sysctl(mib, nitems(mib), buf, &len, NULL, 0) == -1) { 96 | if (errno == ENOMEM) 97 | goto retry; 98 | goto error; 99 | } 100 | 101 | bestp = NULL; 102 | for (i = 0; i < len / sizeof (struct kinfo_proc); i++) { 103 | if (buf[i].kp_tdev != sb.st_rdev) 104 | continue; 105 | if (bestp == NULL) 106 | bestp = &buf[i]; 107 | else 108 | bestp = cmp_procs(&buf[i], bestp); 109 | } 110 | 111 | name = NULL; 112 | if (bestp != NULL) 113 | name = strdup(bestp->kp_comm); 114 | 115 | free(buf); 116 | return (name); 117 | 118 | error: 119 | free(buf); 120 | return (NULL); 121 | } 122 | 123 | char * 124 | osdep_get_cwd(pid_t pid) 125 | { 126 | return (NULL); 127 | } 128 | 129 | struct event_base * 130 | osdep_event_init(void) 131 | { 132 | return (event_init()); 133 | } 134 | -------------------------------------------------------------------------------- /osdep-hpux.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | char * 26 | osdep_get_name(unused int fd, unused char *tty) 27 | { 28 | return (NULL); 29 | } 30 | 31 | char * 32 | osdep_get_cwd(pid_t pid) 33 | { 34 | return (NULL); 35 | } 36 | 37 | struct event_base * 38 | osdep_event_init(void) 39 | { 40 | return (event_init()); 41 | } 42 | -------------------------------------------------------------------------------- /osdep-linux.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "tmux.h" 28 | 29 | char * 30 | osdep_get_name(int fd, unused char *tty) 31 | { 32 | FILE *f; 33 | char *path, *buf; 34 | size_t len; 35 | int ch; 36 | pid_t pgrp; 37 | 38 | if ((pgrp = tcgetpgrp(fd)) == -1) 39 | return (NULL); 40 | 41 | xasprintf(&path, "/proc/%lld/cmdline", (long long) pgrp); 42 | if ((f = fopen(path, "r")) == NULL) { 43 | free(path); 44 | return (NULL); 45 | } 46 | free(path); 47 | 48 | len = 0; 49 | buf = NULL; 50 | while ((ch = fgetc(f)) != EOF) { 51 | if (ch == '\0') 52 | break; 53 | buf = xrealloc(buf, 1, len + 2); 54 | buf[len++] = ch; 55 | } 56 | if (buf != NULL) 57 | buf[len] = '\0'; 58 | 59 | fclose(f); 60 | return (buf); 61 | } 62 | 63 | char * 64 | osdep_get_cwd(pid_t pid) 65 | { 66 | static char target[MAXPATHLEN + 1]; 67 | char *path; 68 | ssize_t n; 69 | 70 | xasprintf(&path, "/proc/%d/cwd", pid); 71 | n = readlink(path, target, MAXPATHLEN); 72 | free(path); 73 | if (n > 0) { 74 | target[n] = '\0'; 75 | return (target); 76 | } 77 | return (NULL); 78 | } 79 | 80 | struct event_base * 81 | osdep_event_init(void) 82 | { 83 | /* 84 | * On Linux, epoll doesn't work on /dev/null (yes, really). 85 | * 86 | * This has been commented because libevent versions up until the very 87 | * latest (1.4 git or 2.0.10) do not handle signals properly when using 88 | * poll or select, causing hangs. 89 | * 90 | */ 91 | /* setenv("EVENT_NOEPOLL", "1", 1); */ 92 | return (event_init()); 93 | } 94 | -------------------------------------------------------------------------------- /osdep-sunos.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Todd Carson 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "tmux.h" 30 | 31 | char * 32 | osdep_get_name(int fd, char *tty) 33 | { 34 | struct psinfo p; 35 | struct stat st; 36 | char *path; 37 | ssize_t bytes; 38 | int f; 39 | pid_t pgrp; 40 | 41 | if ((f = open(tty, O_RDONLY)) < 0) 42 | return (NULL); 43 | 44 | if (fstat(f, &st) != 0 || ioctl(f, TIOCGPGRP, &pgrp) != 0) { 45 | close(f); 46 | return (NULL); 47 | } 48 | close(f); 49 | 50 | xasprintf(&path, "/proc/%u/psinfo", (u_int) pgrp); 51 | f = open(path, O_RDONLY); 52 | free(path); 53 | if (f < 0) 54 | return (NULL); 55 | 56 | bytes = read(f, &p, sizeof(p)); 57 | close(f); 58 | if (bytes != sizeof(p)) 59 | return (NULL); 60 | 61 | if (p.pr_ttydev != st.st_rdev) 62 | return (NULL); 63 | 64 | return (xstrdup(p.pr_fname)); 65 | } 66 | 67 | char * 68 | osdep_get_cwd(pid_t pid) 69 | { 70 | static char target[MAXPATHLEN + 1]; 71 | char *path; 72 | ssize_t n; 73 | 74 | xasprintf(&path, "/proc/%u/path/cwd", (u_int) pid); 75 | n = readlink(path, target, MAXPATHLEN); 76 | free(path); 77 | if (n > 0) { 78 | target[n] = '\0'; 79 | return (target); 80 | } 81 | return (NULL); 82 | } 83 | 84 | struct event_base * 85 | osdep_event_init(void) 86 | { 87 | return (event_init()); 88 | } 89 | -------------------------------------------------------------------------------- /osdep-unknown.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | char * 26 | osdep_get_name(unused int fd, unused char *tty) 27 | { 28 | return (NULL); 29 | } 30 | 31 | char * 32 | osdep_get_cwd(pid_t pid) 33 | { 34 | return (NULL); 35 | } 36 | 37 | struct event_base * 38 | osdep_event_init(void) 39 | { 40 | return (event_init()); 41 | } 42 | -------------------------------------------------------------------------------- /signal.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2007 Nicholas Marriott 5 | * Copyright (c) 2010 Romain Francoise 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 16 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 17 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | struct event ev_sighup; 26 | struct event ev_sigchld; 27 | struct event ev_sigcont; 28 | struct event ev_sigterm; 29 | struct event ev_sigusr1; 30 | struct event ev_sigwinch; 31 | 32 | void 33 | set_signals(void(*handler)(int, short, unused void *)) 34 | { 35 | struct sigaction sigact; 36 | 37 | memset(&sigact, 0, sizeof sigact); 38 | sigemptyset(&sigact.sa_mask); 39 | sigact.sa_flags = SA_RESTART; 40 | sigact.sa_handler = SIG_IGN; 41 | if (sigaction(SIGINT, &sigact, NULL) != 0) 42 | fatal("sigaction failed"); 43 | if (sigaction(SIGPIPE, &sigact, NULL) != 0) 44 | fatal("sigaction failed"); 45 | if (sigaction(SIGUSR2, &sigact, NULL) != 0) 46 | fatal("sigaction failed"); 47 | if (sigaction(SIGTSTP, &sigact, NULL) != 0) 48 | fatal("sigaction failed"); 49 | 50 | signal_set(&ev_sighup, SIGHUP, handler, NULL); 51 | signal_add(&ev_sighup, NULL); 52 | signal_set(&ev_sigchld, SIGCHLD, handler, NULL); 53 | signal_add(&ev_sigchld, NULL); 54 | signal_set(&ev_sigcont, SIGCONT, handler, NULL); 55 | signal_add(&ev_sigcont, NULL); 56 | signal_set(&ev_sigterm, SIGTERM, handler, NULL); 57 | signal_add(&ev_sigterm, NULL); 58 | signal_set(&ev_sigusr1, SIGUSR1, handler, NULL); 59 | signal_add(&ev_sigusr1, NULL); 60 | signal_set(&ev_sigwinch, SIGWINCH, handler, NULL); 61 | signal_add(&ev_sigwinch, NULL); 62 | } 63 | 64 | void 65 | clear_signals(int after_fork) 66 | { 67 | struct sigaction sigact; 68 | 69 | memset(&sigact, 0, sizeof sigact); 70 | sigemptyset(&sigact.sa_mask); 71 | sigact.sa_flags = SA_RESTART; 72 | sigact.sa_handler = SIG_DFL; 73 | if (sigaction(SIGINT, &sigact, NULL) != 0) 74 | fatal("sigaction failed"); 75 | if (sigaction(SIGPIPE, &sigact, NULL) != 0) 76 | fatal("sigaction failed"); 77 | if (sigaction(SIGUSR2, &sigact, NULL) != 0) 78 | fatal("sigaction failed"); 79 | if (sigaction(SIGTSTP, &sigact, NULL) != 0) 80 | fatal("sigaction failed"); 81 | 82 | if (after_fork) { 83 | if (sigaction(SIGHUP, &sigact, NULL) != 0) 84 | fatal("sigaction failed"); 85 | if (sigaction(SIGCHLD, &sigact, NULL) != 0) 86 | fatal("sigaction failed"); 87 | if (sigaction(SIGCONT, &sigact, NULL) != 0) 88 | fatal("sigaction failed"); 89 | if (sigaction(SIGTERM, &sigact, NULL) != 0) 90 | fatal("sigaction failed"); 91 | if (sigaction(SIGUSR1, &sigact, NULL) != 0) 92 | fatal("sigaction failed"); 93 | if (sigaction(SIGWINCH, &sigact, NULL) != 0) 94 | fatal("sigaction failed"); 95 | } else { 96 | event_del(&ev_sighup); 97 | event_del(&ev_sigchld); 98 | event_del(&ev_sigcont); 99 | event_del(&ev_sigterm); 100 | event_del(&ev_sigusr1); 101 | event_del(&ev_sigwinch); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tools/256colors.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Author: Todd Larason 3 | # $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $ 4 | 5 | # use the resources for colors 0-15 - usually more-or-less a 6 | # reproduction of the standard ANSI colors, but possibly more 7 | # pleasing shades 8 | 9 | # colors 16-231 are a 6x6x6 color cube 10 | for ($red = 0; $red < 6; $red++) { 11 | for ($green = 0; $green < 6; $green++) { 12 | for ($blue = 0; $blue < 6; $blue++) { 13 | printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\", 14 | 16 + ($red * 36) + ($green * 6) + $blue, 15 | ($red ? ($red * 40 + 55) : 0), 16 | ($green ? ($green * 40 + 55) : 0), 17 | ($blue ? ($blue * 40 + 55) : 0)); 18 | } 19 | } 20 | } 21 | 22 | # colors 232-255 are a grayscale ramp, intentionally leaving out 23 | # black and white 24 | for ($gray = 0; $gray < 24; $gray++) { 25 | $level = ($gray * 10) + 8; 26 | printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\", 27 | 232 + $gray, $level, $level, $level); 28 | } 29 | 30 | 31 | # display the colors 32 | 33 | # first the system ones: 34 | print "System colors:\n"; 35 | for ($color = 0; $color < 8; $color++) { 36 | print "\x1b[48;5;${color}m "; 37 | } 38 | print "\x1b[0m\n"; 39 | for ($color = 8; $color < 16; $color++) { 40 | print "\x1b[48;5;${color}m "; 41 | } 42 | print "\x1b[0m\n\n"; 43 | 44 | # now the color cube 45 | print "Color cube, 6x6x6:\n"; 46 | for ($green = 0; $green < 6; $green++) { 47 | for ($red = 0; $red < 6; $red++) { 48 | for ($blue = 0; $blue < 6; $blue++) { 49 | $color = 16 + ($red * 36) + ($green * 6) + $blue; 50 | print "\x1b[48;5;${color}m "; 51 | } 52 | print "\x1b[0m "; 53 | } 54 | print "\n"; 55 | } 56 | 57 | 58 | # now the grayscale ramp 59 | print "Grayscale ramp:\n"; 60 | for ($color = 232; $color < 256; $color++) { 61 | print "\x1b[48;5;${color}m "; 62 | } 63 | print "\x1b[0m\n"; 64 | -------------------------------------------------------------------------------- /tools/check-compat.sh: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | 3 | grep "#include" compat.h|while read line; do 4 | grep "$line" *.[ch] compat/*.[ch] 5 | done 6 | -------------------------------------------------------------------------------- /tools/cmp-cvs.sh: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | 3 | rm diff.out 4 | touch diff.out 5 | 6 | for i in *.[ch]; do 7 | diff -u $i /usr/src/usr.bin/tmux/$i >diff.tmp 8 | set -- `wc -l diff.tmp` 9 | [ $1 -eq 8 ] && continue 10 | echo $i 11 | cat diff.tmp >>diff.out 12 | done 13 | -------------------------------------------------------------------------------- /tools/fix-ids.sh: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | 3 | for i in *.[ch] tmux.1; do 4 | (head -1 $i|grep '$OpenBSD' >/dev/null) || continue 5 | mv $i $i~ || exit 6 | sed 's/\$OpenBSD.* \$/$\Id$/' $i~ >$i || exit 7 | echo $i 8 | done 9 | -------------------------------------------------------------------------------- /tools/fuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int 9 | main(void) 10 | { 11 | time_t t; 12 | int i; 13 | 14 | setvbuf(stdout, NULL, _IONBF, 0); 15 | 16 | t = time(NULL); 17 | srandom((u_int) t); 18 | 19 | for (;;) { 20 | putchar('\033'); 21 | 22 | for (i = 0; i < random() % 25; i++) { 23 | if (i > 22) 24 | putchar(';'); 25 | else 26 | putchar(random() % 256); 27 | } 28 | 29 | /* usleep(100); */ 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tools/putty-utf8.sh: -------------------------------------------------------------------------------- 1 | echo -ne \\033%G\\033[?47h\\033%G\\033[?47l 2 | -------------------------------------------------------------------------------- /tty-acs.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2010 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "tmux.h" 24 | 25 | int tty_acs_cmp(const void *, const void *); 26 | 27 | /* Table mapping ACS entries to UTF-8. */ 28 | struct tty_acs_entry { 29 | u_char key; 30 | const char *string; 31 | }; 32 | const struct tty_acs_entry tty_acs_table[] = { 33 | { '+', "\342\206\222" }, 34 | { ',', "\342\206\220" }, 35 | { '-', "\342\206\221" }, 36 | { '.', "\342\206\223" }, 37 | { '0', "\342\226\256" }, 38 | { '`', "\342\227\206" }, 39 | { 'a', "\342\226\222" }, 40 | { 'f', "\302\260" }, 41 | { 'g', "\302\261" }, 42 | { 'h', "\342\226\222" }, 43 | { 'i', "\342\230\203" }, 44 | { 'j', "\342\224\230" }, 45 | { 'k', "\342\224\220" }, 46 | { 'l', "\342\224\214" }, 47 | { 'm', "\342\224\224" }, 48 | { 'n', "\342\224\274" }, 49 | { 'o', "\342\216\272" }, 50 | { 'p', "\342\216\273" }, 51 | { 'q', "\342\224\200" }, 52 | { 'r', "\342\216\274" }, 53 | { 's', "\342\216\275" }, 54 | { 't', "\342\224\234" }, 55 | { 'u', "\342\224\244" }, 56 | { 'v', "\342\224\264" }, 57 | { 'w', "\342\224\254" }, 58 | { 'x', "\342\224\202" }, 59 | { 'y', "\342\211\244" }, 60 | { 'z', "\342\211\245" }, 61 | { '{', "\317\200" }, 62 | { '|', "\342\211\240" }, 63 | { '}', "\302\243" }, 64 | { '~', "\302\267" } 65 | }; 66 | 67 | int 68 | tty_acs_cmp(const void *key, const void *value) 69 | { 70 | const struct tty_acs_entry *entry = value; 71 | u_char ch; 72 | 73 | ch = *(u_char *) key; 74 | return (ch - entry->key); 75 | } 76 | 77 | /* Retrieve ACS to output as a string. */ 78 | const char * 79 | tty_acs_get(struct tty *tty, u_char ch) 80 | { 81 | struct tty_acs_entry *entry; 82 | 83 | /* If not a UTF-8 terminal, use the ACS set. */ 84 | if (!(tty->flags & TTY_UTF8)) { 85 | if (tty->term->acs[ch][0] == '\0') 86 | return (NULL); 87 | return (&tty->term->acs[ch][0]); 88 | } 89 | 90 | /* Otherwise look up the UTF-8 translation. */ 91 | entry = bsearch(&ch, 92 | tty_acs_table, nitems(tty_acs_table), sizeof tty_acs_table[0], 93 | tty_acs_cmp); 94 | if (entry == NULL) 95 | return (NULL); 96 | return (entry->string); 97 | } 98 | -------------------------------------------------------------------------------- /window-clock.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2009 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "tmux.h" 26 | 27 | struct screen *window_clock_init(struct window_pane *); 28 | void window_clock_free(struct window_pane *); 29 | void window_clock_resize(struct window_pane *, u_int, u_int); 30 | void window_clock_key(struct window_pane *, struct session *, int); 31 | void window_clock_timer(struct window_pane *); 32 | 33 | void window_clock_draw_screen(struct window_pane *); 34 | 35 | const struct window_mode window_clock_mode = { 36 | window_clock_init, 37 | window_clock_free, 38 | window_clock_resize, 39 | window_clock_key, 40 | NULL, 41 | window_clock_timer, 42 | }; 43 | 44 | struct window_clock_mode_data { 45 | struct screen screen; 46 | time_t tim; 47 | }; 48 | 49 | struct screen * 50 | window_clock_init(struct window_pane *wp) 51 | { 52 | struct window_clock_mode_data *data; 53 | struct screen *s; 54 | 55 | wp->modedata = data = xmalloc(sizeof *data); 56 | data->tim = time(NULL); 57 | 58 | s = &data->screen; 59 | screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0); 60 | s->mode &= ~MODE_CURSOR; 61 | 62 | window_clock_draw_screen(wp); 63 | 64 | return (s); 65 | } 66 | 67 | void 68 | window_clock_free(struct window_pane *wp) 69 | { 70 | struct window_clock_mode_data *data = wp->modedata; 71 | 72 | screen_free(&data->screen); 73 | free(data); 74 | } 75 | 76 | void 77 | window_clock_resize(struct window_pane *wp, u_int sx, u_int sy) 78 | { 79 | struct window_clock_mode_data *data = wp->modedata; 80 | struct screen *s = &data->screen; 81 | 82 | screen_resize(s, sx, sy); 83 | window_clock_draw_screen(wp); 84 | } 85 | 86 | /* ARGSUSED */ 87 | void 88 | window_clock_key( 89 | struct window_pane *wp, unused struct session *sess, unused int key) 90 | { 91 | window_pane_reset_mode(wp); 92 | } 93 | 94 | void 95 | window_clock_timer(struct window_pane *wp) 96 | { 97 | struct window_clock_mode_data *data = wp->modedata; 98 | struct tm now, then; 99 | time_t t; 100 | 101 | t = time(NULL); 102 | gmtime_r(&t, &now); 103 | gmtime_r(&data->tim, &then); 104 | if (now.tm_min == then.tm_min) 105 | return; 106 | data->tim = t; 107 | 108 | window_clock_draw_screen(wp); 109 | server_redraw_window(wp->window); 110 | } 111 | 112 | void 113 | window_clock_draw_screen(struct window_pane *wp) 114 | { 115 | struct window_clock_mode_data *data = wp->modedata; 116 | struct screen_write_ctx ctx; 117 | int colour, style; 118 | 119 | colour = options_get_number(&wp->window->options, "clock-mode-colour"); 120 | style = options_get_number(&wp->window->options, "clock-mode-style"); 121 | 122 | screen_write_start(&ctx, NULL, &data->screen); 123 | clock_draw(&ctx, colour, style); 124 | screen_write_stop(&ctx); 125 | } 126 | -------------------------------------------------------------------------------- /www/images/tmux3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThomasAdam/tmux-ARCHIVED/a043b975ca0ed13d590fe334b36a896172c44ab7/www/images/tmux3.png -------------------------------------------------------------------------------- /www/images/tmux4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThomasAdam/tmux-ARCHIVED/a043b975ca0ed13d590fe334b36a896172c44ab7/www/images/tmux4.png -------------------------------------------------------------------------------- /www/images/tmux5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThomasAdam/tmux-ARCHIVED/a043b975ca0ed13d590fe334b36a896172c44ab7/www/images/tmux5.png -------------------------------------------------------------------------------- /www/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Sans-Serif; 3 | font-size: 10pt; 4 | background-color: white; 5 | } 6 | #body-wrapper { 7 | overflow: auto; 8 | } 9 | #upper-left-title { 10 | font-size:xx-large; 11 | margin-top: 0; 12 | } 13 | #left-menu li { 14 | list-style: none; 15 | margin-top: 1em; 16 | } 17 | .menu-headings { 18 | border-top: 1px solid black; 19 | border-bottom: 1px solid black; 20 | font-weight: bold; 21 | padding: 0.5em; 22 | } 23 | #left-menu-container { 24 | padding-right: 0.5em; 25 | margin-top: 0.5em; 26 | margin-bottom: 0.5em; 27 | margin-right: 0.5em; 28 | border-right: 3px solid black; 29 | text-align: right; 30 | width: 12em; 31 | float: left; 32 | } 33 | #main-content-wrapper { 34 | margin-left: 2em; 35 | margin-right: 4em; 36 | } 37 | #main-content-wrapper li { 38 | list-style: disc; 39 | margin-left: 12em 40 | } 41 | #screenshots { 42 | text-align: center; 43 | margin: 1em; 44 | margin-left: 10em; 45 | } 46 | #screenshots img { 47 | text-align: center; 48 | margin: 0.5em; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /xmalloc.c: -------------------------------------------------------------------------------- 1 | /* $Id$ */ 2 | 3 | /* 4 | * Copyright (c) 2004 Nicholas Marriott 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "tmux.h" 27 | 28 | char * 29 | xstrdup(const char *s) 30 | { 31 | char *ptr; 32 | size_t len; 33 | 34 | len = strlen(s) + 1; 35 | ptr = xmalloc(len); 36 | 37 | strlcpy(ptr, s, len); 38 | return (ptr); 39 | } 40 | 41 | void * 42 | xcalloc(size_t nmemb, size_t size) 43 | { 44 | void *ptr; 45 | 46 | if (size == 0 || nmemb == 0) 47 | fatalx("zero size"); 48 | if (SIZE_MAX / nmemb < size) 49 | fatalx("nmemb * size > SIZE_MAX"); 50 | if ((ptr = calloc(nmemb, size)) == NULL) 51 | fatal("xcalloc failed"); 52 | 53 | return (ptr); 54 | } 55 | 56 | void * 57 | xmalloc(size_t size) 58 | { 59 | void *ptr; 60 | 61 | if (size == 0) 62 | fatalx("zero size"); 63 | if ((ptr = malloc(size)) == NULL) 64 | fatal("xmalloc failed"); 65 | 66 | return (ptr); 67 | } 68 | 69 | void * 70 | xrealloc(void *oldptr, size_t nmemb, size_t size) 71 | { 72 | size_t newsize = nmemb * size; 73 | void *newptr; 74 | 75 | if (newsize == 0) 76 | fatalx("zero size"); 77 | if (SIZE_MAX / nmemb < size) 78 | fatalx("nmemb * size > SIZE_MAX"); 79 | if ((newptr = realloc(oldptr, newsize)) == NULL) 80 | fatal("xrealloc failed"); 81 | 82 | return (newptr); 83 | } 84 | 85 | int printflike2 86 | xasprintf(char **ret, const char *fmt, ...) 87 | { 88 | va_list ap; 89 | int i; 90 | 91 | va_start(ap, fmt); 92 | i = xvasprintf(ret, fmt, ap); 93 | va_end(ap); 94 | 95 | return (i); 96 | } 97 | 98 | int 99 | xvasprintf(char **ret, const char *fmt, va_list ap) 100 | { 101 | int i; 102 | 103 | i = vasprintf(ret, fmt, ap); 104 | if (i < 0 || *ret == NULL) 105 | fatal("xvasprintf failed"); 106 | 107 | return (i); 108 | } 109 | 110 | int printflike3 111 | xsnprintf(char *buf, size_t len, const char *fmt, ...) 112 | { 113 | va_list ap; 114 | int i; 115 | 116 | va_start(ap, fmt); 117 | i = xvsnprintf(buf, len, fmt, ap); 118 | va_end(ap); 119 | 120 | return (i); 121 | } 122 | 123 | int 124 | xvsnprintf(char *buf, size_t len, const char *fmt, va_list ap) 125 | { 126 | int i; 127 | 128 | if (len > INT_MAX) 129 | fatalx("len > INT_MAX"); 130 | 131 | i = vsnprintf(buf, len, fmt, ap); 132 | if (i < 0) 133 | fatal("vsnprintf failed"); 134 | 135 | return (i); 136 | } 137 | --------------------------------------------------------------------------------