├── .cvsignore ├── .gitignore ├── CHANGES ├── FAQ ├── Makefile.am ├── NOTES ├── 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-session.c ├── cmd-choose-window.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-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 ├── 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 ├── environ.c ├── examples ├── bash_completion_tmux.sh ├── h-boetes.conf ├── n-marriott.conf ├── screen-keys.conf ├── t-williams.conf ├── tmux.vim ├── tmux_backup.sh └── vim-keys.conf ├── 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-string.c ├── layout.c ├── log.c ├── mode-key.c ├── names.c ├── options-table.c ├── options.c ├── osdep-aix.c ├── osdep-darwin.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 /.cvsignore: -------------------------------------------------------------------------------- 1 | tmux 2 | tmux*.log 3 | tmux*.out 4 | regress 5 | releases 6 | saved 7 | patchsets 8 | config.h 9 | config.mk 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | config.log 6 | config.status 7 | configure 8 | etc/ 9 | tags 10 | *.patch 11 | tree-notes 12 | .deps 13 | *.sw* 14 | -------------------------------------------------------------------------------- /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 | Since the 1.2 release that tmux depends on libevent. Download it from: 13 | 14 | http://www.monkey.org/~provos/libevent/ 15 | 16 | tmux consists of a server part and multiple clients. The server is created when 17 | required and runs continuously unless killed by the user. Clients access the 18 | server through a socket in /tmp. Multiple sessions may be created on a single 19 | server and attached to a number of clients. Each session may then have a number 20 | of windows and windows may be linked to a number of sessions. Commands are 21 | available to create, rename and destroy windows and sessions; to attach and 22 | detach sessions from client terminals; to set configuration options; to split 23 | windows into several simultaneously displayed panes; and to bind and unbind 24 | command keys (invoked preceded by a prefix key, by default ctrl-b). Please see 25 | the tmux(1) man page for further information. 26 | 27 | A more extensive, but rough, todo list is included in the TODO file. 28 | 29 | tmux also depends on several features of the client terminal (TERM), if these 30 | are missing it may refuse to run, or not behave correctly. 31 | 32 | A Vim syntax file is available in the examples directory. To install it: 33 | 34 | - Drop the file in the syntax directory in your runtimepath (such as 35 | ~/.vim/syntax/tmux.vim). 36 | - Make the filetype recognisable by adding the following to filetype.vim 37 | in your runtimepath (~/.vim/filetype.vim): 38 | 39 | augroup filetypedetect 40 | au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux 41 | augroup END 42 | 43 | - Switch on syntax highlighting by adding "syntax enable" to your vimrc file. 44 | 45 | For debugging, running tmux with -v or -vv will generate server and client log 46 | files in the current directory. 47 | 48 | tmux mailing lists are available; visit: 49 | 50 | https://sourceforge.net/mail/?group_id=200378 51 | 52 | Bug reports, feature suggestions and especially code contributions are most 53 | welcome. Please send by email to: 54 | 55 | nicm@users.sf.net 56 | 57 | This file and the CHANGES, FAQ and TODO files are licensed under the ISC 58 | license. Files under examples/ remain copyright their authors unless otherwise 59 | stated in the file but permission has been received to distribute them with 60 | tmux. All other files have a license and copyright notice at their 61 | start. Please contact me with any queries. 62 | 63 | -- Nicholas Marriott 64 | 65 | $Id: NOTES,v 1.55 2011/01/03 23:58:10 tcunha Exp $ 66 | -------------------------------------------------------------------------------- /attributes.c: -------------------------------------------------------------------------------- 1 | /* $Id: attributes.c,v 1.4 2010/06/05 23:54:51 tcunha Exp $ */ 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 | 30 | if (attr == 0) 31 | return ("none"); 32 | 33 | buf[0] = '\0'; 34 | if (attr & GRID_ATTR_BRIGHT) 35 | strlcat(buf, "bright,", sizeof (buf)); 36 | if (attr & GRID_ATTR_DIM) 37 | strlcat(buf, "dim,", sizeof (buf)); 38 | if (attr & GRID_ATTR_UNDERSCORE) 39 | strlcat(buf, "underscore,", sizeof (buf)); 40 | if (attr & GRID_ATTR_BLINK) 41 | strlcat(buf, "blink,", sizeof (buf)); 42 | if (attr & GRID_ATTR_REVERSE) 43 | strlcat(buf, "reverse,", sizeof (buf)); 44 | if (attr & GRID_ATTR_HIDDEN) 45 | strlcat(buf, "hidden,", sizeof (buf)); 46 | if (attr & GRID_ATTR_ITALICS) 47 | strlcat(buf, "italics,", sizeof (buf)); 48 | if (*buf != '\0') 49 | *(strrchr(buf, ',')) = '\0'; 50 | 51 | return (buf); 52 | } 53 | 54 | int 55 | attributes_fromstring(const char *str) 56 | { 57 | const char delimiters[] = " ,|"; 58 | u_char attr; 59 | size_t end; 60 | 61 | if (*str == '\0' || strcspn(str, delimiters) == 0) 62 | return (-1); 63 | if (strchr(delimiters, str[strlen(str) - 1]) != NULL) 64 | return (-1); 65 | 66 | if (strcasecmp(str, "default") == 0 || strcasecmp(str, "none") == 0) 67 | return (0); 68 | 69 | attr = 0; 70 | do { 71 | end = strcspn(str, delimiters); 72 | if ((end == 6 && strncasecmp(str, "bright", end) == 0) || 73 | (end == 4 && strncasecmp(str, "bold", end) == 0)) 74 | attr |= GRID_ATTR_BRIGHT; 75 | else if (end == 3 && strncasecmp(str, "dim", end) == 0) 76 | attr |= GRID_ATTR_DIM; 77 | else if (end == 10 && strncasecmp(str, "underscore", end) == 0) 78 | attr |= GRID_ATTR_UNDERSCORE; 79 | else if (end == 5 && strncasecmp(str, "blink", end) == 0) 80 | attr |= GRID_ATTR_BLINK; 81 | else if (end == 7 && strncasecmp(str, "reverse", end) == 0) 82 | attr |= GRID_ATTR_REVERSE; 83 | else if (end == 6 && strncasecmp(str, "hidden", end) == 0) 84 | attr |= GRID_ATTR_HIDDEN; 85 | else if (end == 7 && strncasecmp(str, "italics", end) == 0) 86 | attr |= GRID_ATTR_ITALICS; 87 | else 88 | return (-1); 89 | str += end + strspn(str + end, delimiters); 90 | } while (*str != '\0'); 91 | 92 | return (attr); 93 | } 94 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id: autogen.sh,v 1.2 2010/12/31 22:13:48 nicm Exp $ 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: cmd-attach-session.c,v 1.40 2011/04/06 22:24:00 nicm Exp $ */ 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 | * Attach existing session to the current terminal. 25 | */ 26 | 27 | int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_attach_session_entry = { 30 | "attach-session", "attach", 31 | "drt:", 0, 0, 32 | "[-dr] " CMD_TARGET_SESSION_USAGE, 33 | CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, 34 | NULL, 35 | NULL, 36 | cmd_attach_session_exec 37 | }; 38 | 39 | int 40 | cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct session *s; 44 | struct client *c; 45 | const char *update; 46 | char *overrides, *cause; 47 | u_int i; 48 | 49 | if (RB_EMPTY(&sessions)) { 50 | ctx->error(ctx, "no sessions"); 51 | return (-1); 52 | } 53 | 54 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL) 55 | return (-1); 56 | 57 | if (ctx->cmdclient == NULL && ctx->curclient == NULL) 58 | return (0); 59 | 60 | if (ctx->cmdclient == NULL) { 61 | if (args_has(self->args, 'd')) { 62 | /* 63 | * Can't use server_write_session in case attaching to 64 | * the same session as currently attached to. 65 | */ 66 | for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 67 | c = ARRAY_ITEM(&clients, i); 68 | if (c == NULL || c->session != s) 69 | continue; 70 | if (c == ctx->curclient) 71 | continue; 72 | server_write_client(c, MSG_DETACH, NULL, 0); 73 | } 74 | } 75 | 76 | ctx->curclient->session = s; 77 | session_update_activity(s); 78 | server_redraw_client(ctx->curclient); 79 | } else { 80 | if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { 81 | ctx->error(ctx, "not a terminal"); 82 | return (-1); 83 | } 84 | 85 | overrides = 86 | options_get_string(&s->options, "terminal-overrides"); 87 | if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) { 88 | ctx->error(ctx, "terminal open failed: %s", cause); 89 | xfree(cause); 90 | return (-1); 91 | } 92 | 93 | if (args_has(self->args, 'r')) 94 | ctx->cmdclient->flags |= CLIENT_READONLY; 95 | 96 | if (args_has(self->args, 'd')) 97 | server_write_session(s, MSG_DETACH, NULL, 0); 98 | 99 | ctx->cmdclient->session = s; 100 | session_update_activity(s); 101 | server_write_client(ctx->cmdclient, MSG_READY, NULL, 0); 102 | 103 | update = options_get_string(&s->options, "update-environment"); 104 | environ_update(update, &ctx->cmdclient->environ, &s->environ); 105 | 106 | server_redraw_client(ctx->cmdclient); 107 | } 108 | recalculate_sizes(); 109 | server_update_socket(); 110 | 111 | return (1); /* 1 means don't tell command client to exit */ 112 | } 113 | -------------------------------------------------------------------------------- /cmd-bind-key.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-bind-key.c,v 1.31 2011/01/22 00:00:23 tcunha Exp $ */ 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 | * Bind a key to a command, this recurses through cmd_*. 27 | */ 28 | 29 | int cmd_bind_key_check(struct args *); 30 | int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | int cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int); 33 | 34 | const struct cmd_entry cmd_bind_key_entry = { 35 | "bind-key", "bind", 36 | "cnrt:", 1, -1, 37 | "[-cnr] [-t key-table] key command [arguments]", 38 | 0, 39 | NULL, 40 | cmd_bind_key_check, 41 | cmd_bind_key_exec 42 | }; 43 | 44 | int 45 | cmd_bind_key_check(struct args *args) 46 | { 47 | if (args_has(args, 't')) { 48 | if (args->argc != 2) 49 | return (-1); 50 | } else { 51 | if (args->argc < 2) 52 | return (-1); 53 | } 54 | return (0); 55 | } 56 | 57 | int 58 | cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx) 59 | { 60 | struct args *args = self->args; 61 | char *cause; 62 | struct cmd_list *cmdlist; 63 | int key; 64 | 65 | key = key_string_lookup_string(args->argv[0]); 66 | if (key == KEYC_NONE) { 67 | ctx->error(ctx, "unknown key: %s", args->argv[0]); 68 | return (-1); 69 | } 70 | 71 | if (args_has(args, 't')) 72 | return (cmd_bind_key_table(self, ctx, key)); 73 | 74 | cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause); 75 | if (cmdlist == NULL) { 76 | ctx->error(ctx, "%s", cause); 77 | xfree(cause); 78 | return (-1); 79 | } 80 | 81 | if (!args_has(args, 'n')) 82 | key |= KEYC_PREFIX; 83 | key_bindings_add(key, args_has(args, 'r'), cmdlist); 84 | return (0); 85 | } 86 | 87 | int 88 | cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key) 89 | { 90 | struct args *args = self->args; 91 | const char *tablename; 92 | const struct mode_key_table *mtab; 93 | struct mode_key_binding *mbind, mtmp; 94 | enum mode_key_cmd cmd; 95 | 96 | tablename = args_get(args, 't'); 97 | if ((mtab = mode_key_findtable(tablename)) == NULL) { 98 | ctx->error(ctx, "unknown key table: %s", tablename); 99 | return (-1); 100 | } 101 | 102 | cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]); 103 | if (cmd == MODEKEY_NONE) { 104 | ctx->error(ctx, "unknown command: %s", args->argv[1]); 105 | return (-1); 106 | } 107 | 108 | mtmp.key = key; 109 | mtmp.mode = !!args_has(args, 'c'); 110 | if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) { 111 | mbind->cmd = cmd; 112 | return (0); 113 | } 114 | mbind = xmalloc(sizeof *mbind); 115 | mbind->key = mtmp.key; 116 | mbind->mode = mtmp.mode; 117 | mbind->cmd = cmd; 118 | SPLAY_INSERT(mode_key_tree, mtab->tree, mbind); 119 | return (0); 120 | } 121 | -------------------------------------------------------------------------------- /cmd-break-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-break-pane.c,v 1.13 2011/05/18 20:32:47 tcunha Exp $ */ 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 | int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_break_pane_entry = { 32 | "break-pane", "breakp", 33 | "dt:", 0, 0, 34 | "[-d] " CMD_TARGET_PANE_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_break_pane_exec 39 | }; 40 | 41 | int 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 *cause; 50 | int base_idx; 51 | 52 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) 53 | return (-1); 54 | 55 | if (window_count_panes(wl->window) == 1) { 56 | ctx->error(ctx, "can't break with only one pane"); 57 | return (-1); 58 | } 59 | 60 | w = wl->window; 61 | TAILQ_REMOVE(&w->panes, wp, entry); 62 | if (wp == w->active) { 63 | w->active = w->last; 64 | w->last = NULL; 65 | if (w->active == NULL) { 66 | w->active = TAILQ_PREV(wp, window_panes, entry); 67 | if (w->active == NULL) 68 | w->active = TAILQ_NEXT(wp, entry); 69 | } 70 | } else if (wp == w->last) 71 | w->last = NULL; 72 | layout_close_pane(wp); 73 | 74 | w = wp->window = window_create1(s->sx, s->sy); 75 | TAILQ_INSERT_HEAD(&w->panes, wp, entry); 76 | w->active = wp; 77 | w->name = default_window_name(w); 78 | layout_init(w); 79 | 80 | base_idx = options_get_number(&s->options, "base-index"); 81 | wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */ 82 | if (!args_has(self->args, 'd')) 83 | session_select(s, wl->idx); 84 | 85 | server_redraw_session(s); 86 | server_status_session_group(s); 87 | 88 | return (0); 89 | } 90 | -------------------------------------------------------------------------------- /cmd-capture-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-capture-pane.c,v 1.8 2011/05/18 20:31:00 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 56 | s = &wp->base; 57 | gd = s->grid; 58 | 59 | buf = NULL; 60 | len = 0; 61 | 62 | n = args_strtonum(args, 'S', SHRT_MIN, SHRT_MAX, &cause); 63 | if (cause != NULL) { 64 | top = gd->hsize; 65 | xfree(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', SHRT_MIN, SHRT_MAX, &cause); 74 | if (cause != NULL) { 75 | bottom = gd->hsize + gd->sy - 1; 76 | xfree(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 | xfree(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 (0); 107 | } 108 | 109 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 110 | if (cause != NULL) { 111 | ctx->error(ctx, "buffer %s", cause); 112 | xfree(cause); 113 | return (-1); 114 | } 115 | 116 | if (paste_replace(&global_buffers, buffer, buf, len) != 0) { 117 | ctx->error(ctx, "no buffer %d", buffer); 118 | xfree(buf); 119 | return (-1); 120 | } 121 | 122 | return (0); 123 | } 124 | -------------------------------------------------------------------------------- /cmd-clear-history.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-clear-history.c,v 1.9 2011/01/07 14:45:33 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 48 | gd = wp->base.grid; 49 | 50 | grid_move_lines(gd, 0, gd->hsize, gd->sy); 51 | gd->hsize = 0; 52 | 53 | return (0); 54 | } 55 | -------------------------------------------------------------------------------- /cmd-clock-mode.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-clock-mode.c,v 1.8 2011/01/07 14:45:33 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 47 | 48 | window_pane_set_mode(wp, &window_clock_mode); 49 | 50 | return (0); 51 | } 52 | -------------------------------------------------------------------------------- /cmd-copy-mode.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-copy-mode.c,v 1.29 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 56 | 57 | if (window_pane_set_mode(wp, &window_copy_mode) != 0) 58 | return (0); 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 (0); 64 | } 65 | -------------------------------------------------------------------------------- /cmd-delete-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-delete-buffer.c,v 1.10 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (0); 51 | } 52 | 53 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 54 | if (cause != NULL) { 55 | ctx->error(ctx, "buffer %s", cause); 56 | xfree(cause); 57 | return (-1); 58 | } 59 | 60 | if (paste_free_index(&global_buffers, buffer) != 0) { 61 | ctx->error(ctx, "no buffer %d", buffer); 62 | return (-1); 63 | } 64 | 65 | return (0); 66 | } 67 | -------------------------------------------------------------------------------- /cmd-detach-client.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-detach-client.c,v 1.15 2011/04/18 21:06:25 nicm Exp $ */ 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 | int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_detach_client_entry = { 30 | "detach-client", "detach", 31 | "s:t:P", 0, 0, 32 | "[-P] [-s target-session] " CMD_TARGET_CLIENT_USAGE, 33 | CMD_READONLY, 34 | NULL, 35 | NULL, 36 | cmd_detach_client_exec 37 | }; 38 | 39 | int 40 | cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct client *c; 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 (-1); 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 (-1); 67 | 68 | server_write_client(c, msgtype, NULL, 0); 69 | } 70 | 71 | return (0); 72 | } 73 | -------------------------------------------------------------------------------- /cmd-display-message.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-display-message.c,v 1.10 2011/04/06 22:24:20 nicm Exp $ */ 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 | 23 | #include "tmux.h" 24 | 25 | /* 26 | * Displays a message in the status line. 27 | */ 28 | 29 | int cmd_display_message_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_display_message_entry = { 32 | "display-message", "display", 33 | "c:pt:", 0, 1, 34 | "[-p] [-c target-client] [-t target-pane] [message]", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_display_message_exec 39 | }; 40 | 41 | int 42 | cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct client *c; 46 | struct session *s; 47 | struct winlink *wl; 48 | struct window_pane *wp; 49 | const char *template; 50 | char *msg; 51 | 52 | if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) 53 | return (-1); 54 | 55 | if (args_has(args, 't') != 0) { 56 | wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); 57 | if (wl == NULL) 58 | return (-1); 59 | } else { 60 | s = NULL; 61 | wl = NULL; 62 | wp = NULL; 63 | } 64 | 65 | if (args->argc == 0) 66 | template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)"; 67 | else 68 | template = args->argv[0]; 69 | 70 | msg = status_replace(c, s, wl, wp, template, time(NULL), 0); 71 | if (args_has(self->args, 'p')) 72 | ctx->print(ctx, "%s", msg); 73 | else 74 | status_message_set(c, "%s", msg); 75 | xfree(msg); 76 | 77 | return (0); 78 | } 79 | -------------------------------------------------------------------------------- /cmd-display-panes.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-display-panes.c,v 1.3 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 47 | 48 | server_set_identify(c); 49 | 50 | return (0); 51 | } 52 | -------------------------------------------------------------------------------- /cmd-has-session.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-has-session.c,v 1.17 2011/04/06 22:24:00 nicm Exp $ */ 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 | int 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 | int 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 (-1); 46 | 47 | return (0); 48 | } 49 | -------------------------------------------------------------------------------- /cmd-if-shell.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-if-shell.c,v 1.12 2011/02/15 15:20:03 tcunha Exp $ */ 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 | 25 | #include "tmux.h" 26 | 27 | /* 28 | * Executes a tmux command if a shell command returns true. 29 | */ 30 | 31 | int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | void cmd_if_shell_callback(struct job *); 34 | void cmd_if_shell_free(void *); 35 | 36 | const struct cmd_entry cmd_if_shell_entry = { 37 | "if-shell", "if", 38 | "", 2, 2, 39 | "shell-command command", 40 | 0, 41 | NULL, 42 | NULL, 43 | cmd_if_shell_exec 44 | }; 45 | 46 | struct cmd_if_shell_data { 47 | char *cmd; 48 | struct cmd_ctx ctx; 49 | }; 50 | 51 | int 52 | cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) 53 | { 54 | struct args *args = self->args; 55 | struct cmd_if_shell_data *cdata; 56 | const char *shellcmd = args->argv[0]; 57 | 58 | cdata = xmalloc(sizeof *cdata); 59 | cdata->cmd = xstrdup(args->argv[1]); 60 | memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); 61 | 62 | if (ctx->cmdclient != NULL) 63 | ctx->cmdclient->references++; 64 | if (ctx->curclient != NULL) 65 | ctx->curclient->references++; 66 | 67 | job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata); 68 | 69 | return (1); /* don't let client exit */ 70 | } 71 | 72 | void 73 | cmd_if_shell_callback(struct job *job) 74 | { 75 | struct cmd_if_shell_data *cdata = job->data; 76 | struct cmd_ctx *ctx = &cdata->ctx; 77 | struct cmd_list *cmdlist; 78 | char *cause; 79 | 80 | if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) 81 | return; 82 | 83 | if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) { 84 | if (cause != NULL) { 85 | ctx->error(ctx, "%s", cause); 86 | xfree(cause); 87 | } 88 | return; 89 | } 90 | 91 | if (cmd_list_exec(cmdlist, ctx) < 0) { 92 | cmd_list_free(cmdlist); 93 | return; 94 | } 95 | 96 | cmd_list_free(cmdlist); 97 | } 98 | 99 | void 100 | cmd_if_shell_free(void *data) 101 | { 102 | struct cmd_if_shell_data *cdata = data; 103 | struct cmd_ctx *ctx = &cdata->ctx; 104 | struct msg_exit_data exitdata; 105 | 106 | if (ctx->cmdclient != NULL) { 107 | ctx->cmdclient->references--; 108 | exitdata.retcode = ctx->cmdclient->retcode; 109 | ctx->cmdclient->flags |= CLIENT_EXIT; 110 | } 111 | if (ctx->curclient != NULL) 112 | ctx->curclient->references--; 113 | 114 | xfree(cdata->cmd); 115 | xfree(cdata); 116 | } 117 | -------------------------------------------------------------------------------- /cmd-kill-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-kill-pane.c,v 1.16 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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, *nextwp, *wp; 47 | 48 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) 49 | return (-1); 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 (0); 56 | } 57 | 58 | if (args_has(self->args, 'a')) { 59 | loopwp = TAILQ_FIRST(&wl->window->panes); 60 | while (loopwp != NULL) { 61 | nextwp = TAILQ_NEXT(loopwp, entry); 62 | if (loopwp != wp) { 63 | layout_close_pane(loopwp); 64 | window_remove_pane(wl->window, loopwp); 65 | } 66 | loopwp = nextwp; 67 | } 68 | } else { 69 | layout_close_pane(wp); 70 | window_remove_pane(wl->window, wp); 71 | } 72 | server_redraw_window(wl->window); 73 | 74 | return (0); 75 | } 76 | -------------------------------------------------------------------------------- /cmd-kill-server.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-kill-server.c,v 1.12 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 44 | cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) 45 | { 46 | kill(getpid(), SIGTERM); 47 | 48 | return (0); 49 | } 50 | -------------------------------------------------------------------------------- /cmd-kill-session.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-kill-session.c,v 1.20 2011/04/06 22:24:00 nicm Exp $ */ 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 | int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_kill_session_entry = { 33 | "kill-session", NULL, 34 | "t:", 0, 0, 35 | CMD_TARGET_SESSION_USAGE, 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_kill_session_exec 40 | }; 41 | 42 | int 43 | cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct args *args = self->args; 46 | struct session *s; 47 | 48 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 49 | return (-1); 50 | 51 | server_destroy_session(s); 52 | session_destroy(s); 53 | 54 | return (0); 55 | } 56 | -------------------------------------------------------------------------------- /cmd-kill-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-kill-window.c,v 1.22 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_kill_window_entry = { 30 | "kill-window", "killw", 31 | "t:", 0, 0, 32 | CMD_TARGET_WINDOW_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_kill_window_exec 37 | }; 38 | 39 | int 40 | cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct winlink *wl; 44 | 45 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) 46 | return (-1); 47 | 48 | server_kill_window(wl->window); 49 | recalculate_sizes(); 50 | 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /cmd-link-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-link-window.c,v 1.37 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 52 | if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) 53 | return (-1); 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 | xfree(cause); 60 | return (-1); 61 | } 62 | recalculate_sizes(); 63 | 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /cmd-list-buffers.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-list-buffers.c,v 1.18 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * List paste buffers. 27 | */ 28 | 29 | int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_list_buffers_entry = { 32 | "list-buffers", "lsb", 33 | "", 0, 0, 34 | "", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_list_buffers_exec 39 | }; 40 | 41 | /* ARGSUSED */ 42 | int 43 | cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx) 44 | { 45 | struct paste_buffer *pb; 46 | u_int idx; 47 | char *tmp; 48 | 49 | idx = 0; 50 | while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) { 51 | tmp = paste_print(pb, 50); 52 | ctx->print(ctx, 53 | "%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp); 54 | xfree(tmp); 55 | } 56 | 57 | return (0); 58 | } 59 | -------------------------------------------------------------------------------- /cmd-list-clients.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-list-clients.c,v 1.22 2011/04/18 21:07:11 nicm Exp $ */ 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 all clients. 28 | */ 29 | 30 | int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_list_clients_entry = { 33 | "list-clients", "lsc", 34 | "t:", 0, 0, 35 | CMD_TARGET_SESSION_USAGE, 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_list_clients_exec 40 | }; 41 | 42 | /* ARGSUSED */ 43 | int 44 | cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx) 45 | { 46 | struct args *args = self->args; 47 | struct client *c; 48 | struct session *s; 49 | u_int i; 50 | const char *s_utf8; 51 | 52 | if (args_has(args, 't')) { 53 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 54 | if (s == NULL) 55 | return (-1); 56 | } else 57 | s = NULL; 58 | 59 | for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 60 | c = ARRAY_ITEM(&clients, i); 61 | if (c == NULL || c->session == NULL) 62 | continue; 63 | 64 | if (c->tty.flags & TTY_UTF8) 65 | s_utf8 = " (utf8)"; 66 | else 67 | s_utf8 = ""; 68 | 69 | if (s != NULL && s != c->session) 70 | continue; 71 | ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path, 72 | c->session->name, c->tty.sx, c->tty.sy, 73 | c->tty.termname, s_utf8); 74 | } 75 | 76 | return (0); 77 | } 78 | -------------------------------------------------------------------------------- /cmd-list-commands.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-list-commands.c,v 1.8 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (0); 49 | } 50 | -------------------------------------------------------------------------------- /cmd-list-panes.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-list-panes.c,v 1.10 2011/04/06 22:24:00 nicm Exp $ */ 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 | * List panes on given window. 27 | */ 28 | 29 | int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | void cmd_list_panes_server(struct cmd_ctx *); 32 | void cmd_list_panes_session(struct session *, struct cmd_ctx *); 33 | void cmd_list_panes_window(struct winlink *, struct cmd_ctx *); 34 | 35 | const struct cmd_entry cmd_list_panes_entry = { 36 | "list-panes", "lsp", 37 | "ast:", 0, 0, 38 | "[-as] [-t target]", 39 | 0, 40 | NULL, 41 | NULL, 42 | cmd_list_panes_exec 43 | }; 44 | 45 | int 46 | cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx) 47 | { 48 | struct args *args = self->args; 49 | struct session *s; 50 | struct winlink *wl; 51 | 52 | if (args_has(args, 'a')) 53 | cmd_list_panes_server(ctx); 54 | else if (args_has(args, 's')) { 55 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 56 | if (s == NULL) 57 | return (-1); 58 | cmd_list_panes_session(s, ctx); 59 | } else { 60 | wl = cmd_find_window(ctx, args_get(args, 't'), NULL); 61 | if (wl == NULL) 62 | return (-1); 63 | cmd_list_panes_window(wl, ctx); 64 | } 65 | 66 | return (0); 67 | } 68 | 69 | void 70 | cmd_list_panes_server(struct cmd_ctx *ctx) 71 | { 72 | struct session *s; 73 | 74 | RB_FOREACH(s, sessions, &sessions) 75 | cmd_list_panes_session(s, ctx); 76 | } 77 | 78 | void 79 | cmd_list_panes_session(struct session *s, struct cmd_ctx *ctx) 80 | { 81 | struct winlink *wl; 82 | 83 | RB_FOREACH(wl, winlinks, &s->windows) 84 | cmd_list_panes_window(wl, ctx); 85 | } 86 | 87 | void 88 | cmd_list_panes_window(struct winlink *wl, struct cmd_ctx *ctx) 89 | { 90 | struct window_pane *wp; 91 | struct grid *gd; 92 | struct grid_line *gl; 93 | u_int i, n; 94 | unsigned long long size; 95 | 96 | n = 0; 97 | TAILQ_FOREACH(wp, &wl->window->panes, entry) { 98 | gd = wp->base.grid; 99 | 100 | size = 0; 101 | for (i = 0; i < gd->hsize; i++) { 102 | gl = &gd->linedata[i]; 103 | size += gl->cellsize * sizeof *gl->celldata; 104 | size += gl->utf8size * sizeof *gl->utf8data; 105 | } 106 | size += gd->hsize * sizeof *gd->linedata; 107 | 108 | ctx->print(ctx, 109 | "%u: [%ux%u] [history %u/%u, %llu bytes] %%%u%s%s", 110 | n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size, wp->id, 111 | wp == wp->window->active ? " (active)" : "", 112 | wp->fd == -1 ? " (dead)" : ""); 113 | n++; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /cmd-list-sessions.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-list-sessions.c,v 1.27 2011/01/07 14:45:34 tcunha Exp $ */ 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 all sessions. 28 | */ 29 | 30 | int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_list_sessions_entry = { 33 | "list-sessions", "ls", 34 | "", 0, 0, 35 | "", 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_list_sessions_exec 40 | }; 41 | 42 | /* ARGSUSED */ 43 | int 44 | cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx) 45 | { 46 | struct session *s; 47 | struct session_group *sg; 48 | char *tim, tmp[64]; 49 | u_int idx; 50 | time_t t; 51 | 52 | RB_FOREACH(s, sessions, &sessions) { 53 | sg = session_group_find(s); 54 | if (sg == NULL) 55 | *tmp = '\0'; 56 | else { 57 | idx = session_group_index(sg); 58 | xsnprintf(tmp, sizeof tmp, " (group %u)", idx); 59 | } 60 | 61 | t = s->creation_time.tv_sec; 62 | tim = ctime(&t); 63 | *strchr(tim, '\n') = '\0'; 64 | 65 | ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s", 66 | s->name, winlink_count(&s->windows), tim, s->sx, s->sy, 67 | tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)"); 68 | } 69 | 70 | return (0); 71 | } 72 | -------------------------------------------------------------------------------- /cmd-list-windows.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-list-windows.c,v 1.47 2011/04/06 22:24:00 nicm Exp $ */ 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 | * List windows on given session. 27 | */ 28 | 29 | int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | void cmd_list_windows_server(struct cmd_ctx *); 32 | void cmd_list_windows_session(struct session *, struct cmd_ctx *); 33 | 34 | const struct cmd_entry cmd_list_windows_entry = { 35 | "list-windows", "lsw", 36 | "at:", 0, 0, 37 | "[-a] " CMD_TARGET_SESSION_USAGE, 38 | 0, 39 | NULL, 40 | NULL, 41 | cmd_list_windows_exec 42 | }; 43 | 44 | int 45 | cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx) 46 | { 47 | struct args *args = self->args; 48 | struct session *s; 49 | 50 | if (args_has(args, 'a')) 51 | cmd_list_windows_server(ctx); 52 | else { 53 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 54 | if (s == NULL) 55 | return (-1); 56 | cmd_list_windows_session(s, ctx); 57 | } 58 | 59 | return (0); 60 | } 61 | 62 | void 63 | cmd_list_windows_server(struct cmd_ctx *ctx) 64 | { 65 | struct session *s; 66 | 67 | RB_FOREACH(s, sessions, &sessions) 68 | cmd_list_windows_session(s, ctx); 69 | } 70 | 71 | void 72 | cmd_list_windows_session(struct session *s, struct cmd_ctx *ctx) 73 | { 74 | struct winlink *wl; 75 | char *layout; 76 | 77 | RB_FOREACH(wl, winlinks, &s->windows) { 78 | layout = layout_dump(wl->window); 79 | ctx->print(ctx, "%d: %s [%ux%u] [layout %s]%s", 80 | wl->idx, wl->window->name, wl->window->sx, wl->window->sy, 81 | layout, wl == s->curw ? " (active)" : ""); 82 | xfree(layout); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /cmd-lock-server.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-lock-server.c,v 1.12 2011/04/06 22:24:00 nicm Exp $ */ 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 | int 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 | int 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 (-1); 76 | server_lock_session(s); 77 | } else { 78 | if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) 79 | return (-1); 80 | server_lock_client(c); 81 | } 82 | recalculate_sizes(); 83 | 84 | return (0); 85 | } 86 | -------------------------------------------------------------------------------- /cmd-move-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-move-window.c,v 1.14 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int cmd_move_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_move_window_entry = { 32 | "move-window", "movew", 33 | "dks:t:", 0, 0, 34 | "[-dk] " CMD_SRCDST_WINDOW_USAGE, 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_move_window_exec 39 | }; 40 | 41 | int 42 | cmd_move_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 (-1); 52 | if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) 53 | return (-1); 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 move window: %s", cause); 59 | xfree(cause); 60 | return (-1); 61 | } 62 | server_unlink_window(src, wl); 63 | recalculate_sizes(); 64 | 65 | return (0); 66 | } 67 | -------------------------------------------------------------------------------- /cmd-new-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-new-window.c,v 1.49 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * Create a new window. 27 | */ 28 | 29 | int cmd_new_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_new_window_entry = { 32 | "new-window", "neww", 33 | "adkn:Pt:", 0, 1, 34 | "[-adk] [-n window-name] [-t target-window] [command]", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_new_window_exec 39 | }; 40 | 41 | int 42 | cmd_new_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 | char *cmd, *cwd, *cause; 48 | int idx, last, detached; 49 | 50 | if (args_has(args, 'a')) { 51 | wl = cmd_find_window(ctx, args_get(args, 't'), &s); 52 | if (wl == NULL) 53 | return (-1); 54 | idx = wl->idx + 1; 55 | 56 | /* Find the next free index. */ 57 | for (last = idx; last < INT_MAX; last++) { 58 | if (winlink_find_by_index(&s->windows, last) == NULL) 59 | break; 60 | } 61 | if (last == INT_MAX) { 62 | ctx->error(ctx, "no free window indexes"); 63 | return (-1); 64 | } 65 | 66 | /* Move everything from last - 1 to idx up a bit. */ 67 | for (; last > idx; last--) { 68 | wl = winlink_find_by_index(&s->windows, last - 1); 69 | server_link_window(s, wl, s, last, 0, 0, NULL); 70 | server_unlink_window(s, wl); 71 | } 72 | } else { 73 | if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2) 74 | return (-1); 75 | } 76 | detached = args_has(args, 'd'); 77 | 78 | wl = NULL; 79 | if (idx != -1) 80 | wl = winlink_find_by_index(&s->windows, idx); 81 | if (wl != NULL && args_has(args, 'k')) { 82 | /* 83 | * Can't use session_detach as it will destroy session if this 84 | * makes it empty. 85 | */ 86 | wl->flags &= ~WINLINK_ALERTFLAGS; 87 | winlink_stack_remove(&s->lastw, wl); 88 | winlink_remove(&s->windows, wl); 89 | 90 | /* Force select/redraw if current. */ 91 | if (wl == s->curw) { 92 | detached = 0; 93 | s->curw = NULL; 94 | } 95 | } 96 | 97 | if (args->argc == 0) 98 | cmd = options_get_string(&s->options, "default-command"); 99 | else 100 | cmd = args->argv[0]; 101 | cwd = options_get_string(&s->options, "default-path"); 102 | if (*cwd == '\0') { 103 | if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL) 104 | cwd = ctx->cmdclient->cwd; 105 | else 106 | cwd = s->cwd; 107 | } 108 | 109 | if (idx == -1) 110 | idx = -1 - options_get_number(&s->options, "base-index"); 111 | wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause); 112 | if (wl == NULL) { 113 | ctx->error(ctx, "create window failed: %s", cause); 114 | xfree(cause); 115 | return (-1); 116 | } 117 | if (!detached) { 118 | session_select(s, wl->idx); 119 | server_redraw_session_group(s); 120 | } else 121 | server_status_session_group(s); 122 | 123 | if (args_has(args, 'P')) 124 | ctx->print(ctx, "%s:%u", s->name, wl->idx); 125 | return (0); 126 | } 127 | -------------------------------------------------------------------------------- /cmd-paste-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-paste-buffer.c,v 1.31 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * Paste paste buffer if present. 28 | */ 29 | 30 | int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | void cmd_paste_buffer_filter( 33 | struct window_pane *, const char *, size_t, const char *); 34 | 35 | const struct cmd_entry cmd_paste_buffer_entry = { 36 | "paste-buffer", "pasteb", 37 | "db:rs:t:", 0, 0, 38 | "[-dr] [-s separator] [-b buffer-index] [-t target-pane]", 39 | 0, 40 | NULL, 41 | NULL, 42 | cmd_paste_buffer_exec 43 | }; 44 | 45 | int 46 | cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 47 | { 48 | struct args *args = self->args; 49 | struct window_pane *wp; 50 | struct session *s; 51 | struct paste_buffer *pb; 52 | const char *sepstr; 53 | char *cause; 54 | int buffer; 55 | 56 | if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL) 57 | return (-1); 58 | 59 | if (!args_has(args, 'b')) 60 | buffer = -1; 61 | else { 62 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 63 | if (cause != NULL) { 64 | ctx->error(ctx, "buffer %s", cause); 65 | xfree(cause); 66 | return (-1); 67 | } 68 | } 69 | 70 | if (buffer == -1) 71 | pb = paste_get_top(&global_buffers); 72 | else { 73 | pb = paste_get_index(&global_buffers, buffer); 74 | if (pb == NULL) { 75 | ctx->error(ctx, "no buffer %d", buffer); 76 | return (-1); 77 | } 78 | } 79 | 80 | if (pb != NULL) { 81 | sepstr = args_get(args, 's'); 82 | if (sepstr == NULL) { 83 | if (args_has(args, 'r')) 84 | sepstr = "\n"; 85 | else 86 | sepstr = "\r"; 87 | } 88 | cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr); 89 | } 90 | 91 | /* Delete the buffer if -d. */ 92 | if (args_has(args, 'd')) { 93 | if (buffer == -1) 94 | paste_free_top(&global_buffers); 95 | else 96 | paste_free_index(&global_buffers, buffer); 97 | } 98 | 99 | return (0); 100 | } 101 | 102 | /* Add bytes to a buffer and filter '\n' according to separator. */ 103 | void 104 | cmd_paste_buffer_filter( 105 | struct window_pane *wp, const char *data, size_t size, const char *sep) 106 | { 107 | const char *end = data + size; 108 | const char *lf; 109 | size_t seplen; 110 | 111 | seplen = strlen(sep); 112 | while ((lf = memchr(data, '\n', end - data)) != NULL) { 113 | if (lf != data) 114 | bufferevent_write(wp->event, data, lf - data); 115 | bufferevent_write(wp->event, sep, seplen); 116 | data = lf + 1; 117 | } 118 | 119 | if (end != data) 120 | bufferevent_write(wp->event, data, end - data); 121 | } 122 | -------------------------------------------------------------------------------- /cmd-refresh-client.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-refresh-client.c,v 1.12 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_refresh_client_entry = { 30 | "refresh-client", "refresh", 31 | "t:", 0, 0, 32 | CMD_TARGET_CLIENT_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_refresh_client_exec 37 | }; 38 | 39 | int 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 (-1); 47 | 48 | server_redraw_client(c); 49 | 50 | return (0); 51 | } 52 | -------------------------------------------------------------------------------- /cmd-rename-session.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-rename-session.c,v 1.24 2011/04/06 22:29:26 nicm Exp $ */ 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 | int 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 | int 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 (-1); 52 | } 53 | if (session_find(newname) != NULL) { 54 | ctx->error(ctx, "duplicate session: %s", newname); 55 | return (-1); 56 | } 57 | 58 | if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) 59 | return (-1); 60 | 61 | RB_REMOVE(sessions, &sessions, s); 62 | xfree(s->name); 63 | s->name = xstrdup(newname); 64 | RB_INSERT(sessions, &sessions, s); 65 | 66 | server_status_session(s); 67 | 68 | return (0); 69 | } 70 | -------------------------------------------------------------------------------- /cmd-rename-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-rename-window.c,v 1.32 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 50 | 51 | xfree(wl->window->name); 52 | wl->window->name = xstrdup(args->argv[0]); 53 | options_set_number(&wl->window->options, "automatic-rename", 0); 54 | 55 | server_status_window(wl->window); 56 | 57 | return (0); 58 | } 59 | -------------------------------------------------------------------------------- /cmd-resize-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-resize-pane.c,v 1.15 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * Increase or decrease pane size. 27 | */ 28 | 29 | void cmd_resize_pane_key_binding(struct cmd *, int); 30 | int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *); 31 | 32 | const struct cmd_entry cmd_resize_pane_entry = { 33 | "resize-pane", "resizep", 34 | "DLRt:U", 0, 1, 35 | "[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]", 36 | 0, 37 | cmd_resize_pane_key_binding, 38 | NULL, 39 | cmd_resize_pane_exec 40 | }; 41 | 42 | void 43 | cmd_resize_pane_key_binding(struct cmd *self, int key) 44 | { 45 | switch (key) { 46 | case KEYC_UP | KEYC_CTRL: 47 | self->args = args_create(0); 48 | args_set(self->args, 'U', NULL); 49 | break; 50 | case KEYC_DOWN | KEYC_CTRL: 51 | self->args = args_create(0); 52 | args_set(self->args, 'D', NULL); 53 | break; 54 | case KEYC_LEFT | KEYC_CTRL: 55 | self->args = args_create(0); 56 | args_set(self->args, 'L', NULL); 57 | break; 58 | case KEYC_RIGHT | KEYC_CTRL: 59 | self->args = args_create(0); 60 | args_set(self->args, 'R', NULL); 61 | break; 62 | case KEYC_UP | KEYC_ESCAPE: 63 | self->args = args_create(1, "5"); 64 | args_set(self->args, 'U', NULL); 65 | break; 66 | case KEYC_DOWN | KEYC_ESCAPE: 67 | self->args = args_create(1, "5"); 68 | args_set(self->args, 'D', NULL); 69 | break; 70 | case KEYC_LEFT | KEYC_ESCAPE: 71 | self->args = args_create(1, "5"); 72 | args_set(self->args, 'L', NULL); 73 | break; 74 | case KEYC_RIGHT | KEYC_ESCAPE: 75 | self->args = args_create(1, "5"); 76 | args_set(self->args, 'R', NULL); 77 | break; 78 | default: 79 | self->args = args_create(0); 80 | break; 81 | } 82 | } 83 | 84 | int 85 | cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) 86 | { 87 | struct args *args = self->args; 88 | struct winlink *wl; 89 | const char *errstr; 90 | struct window_pane *wp; 91 | u_int adjust; 92 | 93 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) 94 | return (-1); 95 | 96 | if (args->argc == 0) 97 | adjust = 1; 98 | else { 99 | adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr); 100 | if (errstr != NULL) { 101 | ctx->error(ctx, "adjustment %s", errstr); 102 | return (-1); 103 | } 104 | } 105 | 106 | if (args_has(self->args, 'L')) 107 | layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust); 108 | else if (args_has(self->args, 'R')) 109 | layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust); 110 | else if (args_has(self->args, 'U')) 111 | layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust); 112 | else if (args_has(self->args, 'D')) 113 | layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust); 114 | server_redraw_window(wl->window); 115 | 116 | return (0); 117 | } 118 | -------------------------------------------------------------------------------- /cmd-respawn-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-respawn-window.c,v 1.26 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * Respawn a window (restart the command). Kill existing if -k given. 27 | */ 28 | 29 | int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_respawn_window_entry = { 32 | "respawn-window", "respawnw", 33 | "kt:", 0, 1, 34 | "[-k] " CMD_TARGET_WINDOW_USAGE " [command]", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_respawn_window_exec 39 | }; 40 | 41 | int 42 | cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct winlink *wl; 46 | struct window *w; 47 | struct window_pane *wp; 48 | struct session *s; 49 | struct environ env; 50 | const char *cmd; 51 | char *cause; 52 | 53 | if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) 54 | return (-1); 55 | w = wl->window; 56 | 57 | if (!args_has(self->args, 'k')) { 58 | TAILQ_FOREACH(wp, &w->panes, entry) { 59 | if (wp->fd == -1) 60 | continue; 61 | ctx->error(ctx, 62 | "window still active: %s:%d", s->name, wl->idx); 63 | return (-1); 64 | } 65 | } 66 | 67 | environ_init(&env); 68 | environ_copy(&global_environ, &env); 69 | environ_copy(&s->environ, &env); 70 | server_fill_environ(s, &env); 71 | 72 | wp = TAILQ_FIRST(&w->panes); 73 | TAILQ_REMOVE(&w->panes, wp, entry); 74 | layout_free(w); 75 | window_destroy_panes(w); 76 | TAILQ_INSERT_HEAD(&w->panes, wp, entry); 77 | window_pane_resize(wp, w->sx, w->sy); 78 | if (args->argc != 0) 79 | cmd = args->argv[0]; 80 | else 81 | cmd = NULL; 82 | if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) { 83 | ctx->error(ctx, "respawn window failed: %s", cause); 84 | xfree(cause); 85 | environ_free(&env); 86 | server_destroy_pane(wp); 87 | return (-1); 88 | } 89 | layout_init(w); 90 | screen_reinit(&wp->base); 91 | window_set_active_pane(w, wp); 92 | 93 | recalculate_sizes(); 94 | server_redraw_window(w); 95 | 96 | environ_free(&env); 97 | return (0); 98 | } 99 | -------------------------------------------------------------------------------- /cmd-save-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-save-buffer.c,v 1.14 2011/01/07 14:45:34 tcunha Exp $ */ 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 | 25 | #include "tmux.h" 26 | 27 | /* 28 | * Saves a session paste buffer to a file. 29 | */ 30 | 31 | int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *); 32 | 33 | const struct cmd_entry cmd_save_buffer_entry = { 34 | "save-buffer", "saveb", 35 | "ab:", 1, 1, 36 | "[-a] " CMD_BUFFER_USAGE, 37 | 0, 38 | NULL, 39 | NULL, 40 | cmd_save_buffer_exec 41 | }; 42 | 43 | int 44 | cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 45 | { 46 | struct args *args = self->args; 47 | struct client *c = ctx->cmdclient; 48 | struct paste_buffer *pb; 49 | const char *path; 50 | char *cause; 51 | int buffer; 52 | mode_t mask; 53 | FILE *f; 54 | 55 | if (!args_has(args, 'b')) { 56 | if ((pb = paste_get_top(&global_buffers)) == NULL) { 57 | ctx->error(ctx, "no buffers"); 58 | return (-1); 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 | xfree(cause); 65 | return (-1); 66 | } 67 | 68 | pb = paste_get_index(&global_buffers, buffer); 69 | if (pb == NULL) { 70 | ctx->error(ctx, "no buffer %d", buffer); 71 | return (-1); 72 | } 73 | } 74 | 75 | path = args->argv[0]; 76 | if (strcmp(path, "-") == 0) { 77 | if (c == NULL) { 78 | ctx->error(ctx, "%s: can't write to stdout", path); 79 | return (-1); 80 | } 81 | bufferevent_write(c->stdout_event, pb->data, pb->size); 82 | } else { 83 | mask = umask(S_IRWXG | S_IRWXO); 84 | if (args_has(self->args, 'a')) 85 | f = fopen(path, "ab"); 86 | else 87 | f = fopen(path, "wb"); 88 | umask(mask); 89 | if (f == NULL) { 90 | ctx->error(ctx, "%s: %s", path, strerror(errno)); 91 | return (-1); 92 | } 93 | if (fwrite(pb->data, 1, pb->size, f) != pb->size) { 94 | ctx->error(ctx, "%s: fwrite error", path); 95 | fclose(f); 96 | return (-1); 97 | } 98 | fclose(f); 99 | } 100 | 101 | return (0); 102 | } 103 | -------------------------------------------------------------------------------- /cmd-select-pane.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-select-pane.c,v 1.16 2011/02/15 15:25:12 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 77 | 78 | if (wl->window->last == NULL) { 79 | ctx->error(ctx, "no last pane"); 80 | return (-1); 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 (0); 88 | } 89 | 90 | if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) 91 | return (-1); 92 | 93 | if (!window_pane_visible(wp)) { 94 | ctx->error(ctx, "pane not visible"); 95 | return (-1); 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 (-1); 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 (0); 116 | } 117 | -------------------------------------------------------------------------------- /cmd-send-keys.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-send-keys.c,v 1.26 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * Send keys to client. 27 | */ 28 | 29 | int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_send_keys_entry = { 32 | "send-keys", "send", 33 | "t:", 0, -1, 34 | "[-t target-pane] key ...", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_send_keys_exec 39 | }; 40 | 41 | int 42 | cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | struct window_pane *wp; 46 | struct session *s; 47 | const char *str; 48 | int i, key; 49 | 50 | if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL) 51 | return (-1); 52 | 53 | for (i = 0; i < args->argc; i++) { 54 | str = args->argv[i]; 55 | 56 | if ((key = key_string_lookup_string(str)) != KEYC_NONE) { 57 | window_pane_key(wp, s, key); 58 | } else { 59 | for (; *str != '\0'; str++) 60 | window_pane_key(wp, s, *str); 61 | } 62 | } 63 | 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /cmd-send-prefix.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-send-prefix.c,v 1.30 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_send_prefix_entry = { 30 | "send-prefix", NULL, 31 | "t:", 0, 0, 32 | CMD_TARGET_PANE_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_send_prefix_exec 37 | }; 38 | 39 | int 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 | struct keylist *keylist; 46 | 47 | if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL) 48 | return (-1); 49 | 50 | keylist = options_get_data(&s->options, "prefix"); 51 | window_pane_key(wp, s, ARRAY_FIRST(keylist)); 52 | 53 | return (0); 54 | } 55 | -------------------------------------------------------------------------------- /cmd-set-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-set-buffer.c,v 1.14 2011/01/07 14:45:34 tcunha Exp $ */ 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 | * Add or set a session paste buffer. 27 | */ 28 | 29 | int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *); 30 | 31 | const struct cmd_entry cmd_set_buffer_entry = { 32 | "set-buffer", "setb", 33 | "b:", 1, 1, 34 | CMD_BUFFER_USAGE " data", 35 | 0, 36 | NULL, 37 | NULL, 38 | cmd_set_buffer_exec 39 | }; 40 | 41 | int 42 | cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 43 | { 44 | struct args *args = self->args; 45 | u_int limit; 46 | char *pdata, *cause; 47 | size_t psize; 48 | int buffer; 49 | 50 | limit = options_get_number(&global_options, "buffer-limit"); 51 | 52 | pdata = xstrdup(args->argv[0]); 53 | psize = strlen(pdata); 54 | 55 | if (!args_has(args, 'b')) { 56 | paste_add(&global_buffers, pdata, psize, limit); 57 | return (0); 58 | } 59 | 60 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 61 | if (cause != NULL) { 62 | ctx->error(ctx, "buffer %s", cause); 63 | xfree(cause); 64 | return (-1); 65 | } 66 | 67 | if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) { 68 | ctx->error(ctx, "no buffer %d", buffer); 69 | xfree(pdata); 70 | return (-1); 71 | } 72 | 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /cmd-set-environment.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-set-environment.c,v 1.5 2011/04/06 22:24:01 nicm Exp $ */ 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 | int 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 | int 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 (-1); 54 | } 55 | if (strchr(name, '=') != NULL) { 56 | ctx->error(ctx, "variable name contains ="); 57 | return (-1); 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 (-1); 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 (-1); 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 (-1); 83 | } 84 | environ_set(env, name, NULL); 85 | } else { 86 | if (value == NULL) { 87 | ctx->error(ctx, "no value specified"); 88 | return (-1); 89 | } 90 | environ_set(env, name, value); 91 | } 92 | 93 | return (0); 94 | } 95 | -------------------------------------------------------------------------------- /cmd-show-buffer.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-show-buffer.c,v 1.15 2011/04/06 22:24:01 nicm Exp $ */ 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 | * Show a session paste buffer. 25 | */ 26 | 27 | int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_show_buffer_entry = { 30 | "show-buffer", "showb", 31 | "b:", 0, 0, 32 | CMD_BUFFER_USAGE, 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_show_buffer_exec 37 | }; 38 | 39 | int 40 | cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct session *s; 44 | struct paste_buffer *pb; 45 | int buffer; 46 | char *in, *buf, *ptr, *cause; 47 | size_t size, len; 48 | u_int width; 49 | 50 | if ((s = cmd_find_session(ctx, NULL, 0)) == NULL) 51 | return (-1); 52 | 53 | if (!args_has(args, 'b')) { 54 | if ((pb = paste_get_top(&global_buffers)) == NULL) { 55 | ctx->error(ctx, "no buffers"); 56 | return (-1); 57 | } 58 | } else { 59 | buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); 60 | if (cause != NULL) { 61 | ctx->error(ctx, "buffer %s", cause); 62 | xfree(cause); 63 | return (-1); 64 | } 65 | 66 | pb = paste_get_index(&global_buffers, buffer); 67 | if (pb == NULL) { 68 | ctx->error(ctx, "no buffer %d", buffer); 69 | return (-1); 70 | } 71 | } 72 | 73 | size = pb->size; 74 | if (size > SIZE_MAX / 4 - 1) 75 | size = SIZE_MAX / 4 - 1; 76 | in = xmalloc(size * 4 + 1); 77 | strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB); 78 | 79 | width = s->sx; 80 | if (ctx->cmdclient != NULL) 81 | width = ctx->cmdclient->tty.sx; 82 | 83 | buf = xmalloc(width + 1); 84 | len = 0; 85 | 86 | ptr = in; 87 | do { 88 | buf[len++] = *ptr++; 89 | 90 | if (len == width || buf[len - 1] == '\n') { 91 | if (buf[len - 1] == '\n') 92 | len--; 93 | buf[len] = '\0'; 94 | 95 | ctx->print(ctx, "%s", buf); 96 | len = 0; 97 | } 98 | } while (*ptr != '\0'); 99 | 100 | if (len != 0) { 101 | buf[len] = '\0'; 102 | ctx->print(ctx, "%s", buf); 103 | } 104 | xfree(buf); 105 | 106 | xfree(in); 107 | 108 | return (0); 109 | } 110 | -------------------------------------------------------------------------------- /cmd-show-environment.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-show-environment.c,v 1.4 2011/04/06 22:24:01 nicm Exp $ */ 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 | int 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, 0, 35 | "[-g] " CMD_TARGET_SESSION_USAGE, 36 | 0, 37 | NULL, 38 | NULL, 39 | cmd_show_environment_exec 40 | }; 41 | 42 | int 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 (-1); 55 | env = &s->environ; 56 | } 57 | 58 | RB_FOREACH(envent, environ, env) { 59 | if (envent->value != NULL) 60 | ctx->print(ctx, "%s=%s", envent->name, envent->value); 61 | else 62 | ctx->print(ctx, "-%s", envent->name); 63 | } 64 | 65 | return (0); 66 | } 67 | -------------------------------------------------------------------------------- /cmd-show-messages.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-show-messages.c,v 1.3 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 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 (0); 64 | } 65 | -------------------------------------------------------------------------------- /cmd-show-options.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-show-options.c,v 1.25 2011/04/06 22:24:01 nicm Exp $ */ 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 | int 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, 0, 35 | "[-gsw] [-t target-session|target-window]", 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, 0, 45 | "[-g] " CMD_TARGET_WINDOW_USAGE, 46 | 0, 47 | NULL, 48 | NULL, 49 | cmd_show_options_exec 50 | }; 51 | 52 | int 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 (-1); 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 (-1); 85 | oo = &s->options; 86 | } 87 | } 88 | 89 | for (oe = table; oe->name != NULL; oe++) { 90 | if ((o = options_find1(oo, oe->name)) == NULL) 91 | continue; 92 | optval = options_table_print_entry(oe, o); 93 | ctx->print(ctx, "%s %s", oe->name, optval); 94 | } 95 | 96 | return (0); 97 | } 98 | -------------------------------------------------------------------------------- /cmd-source-file.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-source-file.c,v 1.15 2011/01/07 14:45:34 tcunha Exp $ */ 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 "tmux.h" 22 | 23 | /* 24 | * Sources a configuration file. 25 | */ 26 | 27 | int cmd_source_file_exec(struct cmd *, struct cmd_ctx *); 28 | 29 | const struct cmd_entry cmd_source_file_entry = { 30 | "source-file", "source", 31 | "", 1, 1, 32 | "path", 33 | 0, 34 | NULL, 35 | NULL, 36 | cmd_source_file_exec 37 | }; 38 | 39 | int 40 | cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx) 41 | { 42 | struct args *args = self->args; 43 | struct causelist causes; 44 | char *cause; 45 | struct window_pane *wp; 46 | int retval; 47 | u_int i; 48 | 49 | ARRAY_INIT(&causes); 50 | 51 | retval = load_cfg(args->argv[0], ctx, &causes); 52 | if (ARRAY_EMPTY(&causes)) 53 | return (retval); 54 | 55 | if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) { 56 | wp = RB_MIN(sessions, &sessions)->curw->window->active; 57 | window_pane_set_mode(wp, &window_copy_mode); 58 | window_copy_init_for_output(wp); 59 | for (i = 0; i < ARRAY_LENGTH(&causes); i++) { 60 | cause = ARRAY_ITEM(&causes, i); 61 | window_copy_add(wp, "%s", cause); 62 | xfree(cause); 63 | } 64 | } else { 65 | for (i = 0; i < ARRAY_LENGTH(&causes); i++) { 66 | cause = ARRAY_ITEM(&causes, i); 67 | ctx->print(ctx, "%s", cause); 68 | xfree(cause); 69 | } 70 | } 71 | ARRAY_FREE(&causes); 72 | 73 | return (retval); 74 | } 75 | -------------------------------------------------------------------------------- /cmd-start-server.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-start-server.c,v 1.11 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 41 | cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) 42 | { 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /cmd-suspend-client.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-suspend-client.c,v 1.7 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 50 | 51 | tty_stop_tty(&c->tty); 52 | c->flags |= CLIENT_SUSPENDED; 53 | server_write_client(c, MSG_SUSPEND, NULL, 0); 54 | 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /cmd-swap-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-swap-window.c,v 1.20 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 (-1); 54 | target_dst = args_get(args, 't'); 55 | if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL) 56 | return (-1); 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 (-1); 64 | } 65 | 66 | if (wl_dst->window == wl_src->window) 67 | return (0); 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 (0); 87 | } 88 | -------------------------------------------------------------------------------- /cmd-switch-client.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-switch-client.c,v 1.26 2011/04/06 22:24:01 nicm Exp $ */ 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 | int 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:", 0, 0, 36 | "[-lnp] [-c target-client] [-t target-session]", 37 | 0, 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 | int 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 (-1); 69 | 70 | s = NULL; 71 | if (args_has(args, 'n')) { 72 | if ((s = session_next_session(c->session)) == NULL) { 73 | ctx->error(ctx, "can't find next session"); 74 | return (-1); 75 | } 76 | } else if (args_has(args, 'p')) { 77 | if ((s = session_previous_session(c->session)) == NULL) { 78 | ctx->error(ctx, "can't find previous session"); 79 | return (-1); 80 | } 81 | } else if (args_has(args, 'l')) { 82 | if (c->last_session != NULL && session_alive(c->last_session)) 83 | s = c->last_session; 84 | if (s == NULL) { 85 | ctx->error(ctx, "can't find last session"); 86 | return (-1); 87 | } 88 | } else 89 | s = cmd_find_session(ctx, args_get(args, 't'), 0); 90 | if (s == NULL) 91 | return (-1); 92 | 93 | if (c->session != NULL) 94 | c->last_session = c->session; 95 | c->session = s; 96 | session_update_activity(s); 97 | 98 | recalculate_sizes(); 99 | server_check_unattached(); 100 | server_redraw_client(c); 101 | 102 | return (0); 103 | } 104 | -------------------------------------------------------------------------------- /cmd-unbind-key.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-unbind-key.c,v 1.25 2011/01/21 23:46:09 tcunha Exp $ */ 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 | * Unbind key from command. 25 | */ 26 | 27 | int cmd_unbind_key_check(struct args *); 28 | int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *); 29 | 30 | int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int); 31 | 32 | const struct cmd_entry cmd_unbind_key_entry = { 33 | "unbind-key", "unbind", 34 | "acnt:", 0, 1, 35 | "[-acn] [-t key-table] key", 36 | 0, 37 | NULL, 38 | cmd_unbind_key_check, 39 | cmd_unbind_key_exec 40 | }; 41 | 42 | int 43 | cmd_unbind_key_check(struct args *args) 44 | { 45 | if (args_has(args, 'a') && (args->argc != 0 || args_has(args, 't'))) 46 | return (-1); 47 | if (!args_has(args, 'a') && args->argc != 1) 48 | return (-1); 49 | return (0); 50 | } 51 | 52 | int 53 | cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx) 54 | { 55 | struct args *args = self->args; 56 | struct key_binding *bd; 57 | int key; 58 | 59 | if (args_has(args, 'a')) { 60 | while (!SPLAY_EMPTY(&key_bindings)) { 61 | bd = SPLAY_ROOT(&key_bindings); 62 | SPLAY_REMOVE(key_bindings, &key_bindings, bd); 63 | cmd_list_free(bd->cmdlist); 64 | xfree(bd); 65 | } 66 | return (0); 67 | } 68 | 69 | key = key_string_lookup_string(args->argv[0]); 70 | if (key == KEYC_NONE) { 71 | ctx->error(ctx, "unknown key: %s", args->argv[0]); 72 | return (-1); 73 | } 74 | 75 | if (args_has(args, 't')) 76 | return (cmd_unbind_key_table(self, ctx, key)); 77 | 78 | if (!args_has(args, 'n')) 79 | key |= KEYC_PREFIX; 80 | key_bindings_remove(key); 81 | return (0); 82 | } 83 | 84 | int 85 | cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key) 86 | { 87 | struct args *args = self->args; 88 | const char *tablename; 89 | const struct mode_key_table *mtab; 90 | struct mode_key_binding *mbind, mtmp; 91 | 92 | tablename = args_get(args, 't'); 93 | if ((mtab = mode_key_findtable(tablename)) == NULL) { 94 | ctx->error(ctx, "unknown key table: %s", tablename); 95 | return (-1); 96 | } 97 | 98 | mtmp.key = key; 99 | mtmp.mode = !!args_has(args, 'c'); 100 | if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) { 101 | SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind); 102 | xfree(mbind); 103 | } 104 | return (0); 105 | } 106 | -------------------------------------------------------------------------------- /cmd-unlink-window.c: -------------------------------------------------------------------------------- 1 | /* $Id: cmd-unlink-window.c,v 1.22 2011/01/07 14:45:34 tcunha Exp $ */ 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 | int 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 | int 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 (-1); 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 (-1); 64 | } 65 | 66 | server_unlink_window(s, wl); 67 | recalculate_sizes(); 68 | 69 | return (0); 70 | } 71 | -------------------------------------------------------------------------------- /compat/asprintf.c: -------------------------------------------------------------------------------- 1 | /* $Id: asprintf.c,v 1.7 2011/03/04 23:39:41 nicm Exp $ */ 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 | 48 | if ((n = vsnprintf(NULL, 0, fmt, ap)) < 0) 49 | goto error; 50 | 51 | *ret = xmalloc(n + 1); 52 | if ((n = vsnprintf(*ret, n + 1, fmt, ap)) < 0) { 53 | xfree(*ret); 54 | goto error; 55 | } 56 | 57 | return (n); 58 | 59 | error: 60 | *ret = NULL; 61 | return (-1); 62 | } 63 | -------------------------------------------------------------------------------- /compat/closefrom.c: -------------------------------------------------------------------------------- 1 | /* $Id: closefrom.c,v 1.1 2010/10/27 20:21:01 nicm Exp $ */ 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 | /* $OpenBSD: daemon.c,v 1.6 2005/08/08 08:05:33 espie Exp $ */ 2 | /*- 3 | * Copyright (c) 1990, 1993 4 | * The Regents of the University of California. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "tmux.h" 36 | 37 | int 38 | daemon(int nochdir, int noclose) 39 | { 40 | int fd; 41 | 42 | switch (fork()) { 43 | case -1: 44 | return (-1); 45 | case 0: 46 | break; 47 | default: 48 | _exit(0); 49 | } 50 | 51 | if (setsid() == -1) 52 | return (-1); 53 | 54 | if (!nochdir) 55 | (void)chdir("/"); 56 | 57 | if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { 58 | (void)dup2(fd, STDIN_FILENO); 59 | (void)dup2(fd, STDOUT_FILENO); 60 | (void)dup2(fd, STDERR_FILENO); 61 | if (fd > 2) 62 | (void)close (fd); 63 | } 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /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(fp, len) 47 | FILE *fp; 48 | size_t *len; 49 | { 50 | static char *buf = NULL; 51 | static size_t bufsiz = 0; 52 | char *ptr; 53 | 54 | 55 | if (buf == NULL) { 56 | bufsiz = BUFSIZ; 57 | if ((buf = malloc(bufsiz)) == NULL) 58 | return NULL; 59 | } 60 | 61 | if (fgets(buf, bufsiz, fp) == NULL) 62 | return NULL; 63 | 64 | *len = 0; 65 | while ((ptr = strchr(&buf[*len], '\n')) == NULL) { 66 | size_t nbufsiz = bufsiz + BUFSIZ; 67 | char *nbuf = realloc(buf, nbufsiz); 68 | 69 | if (nbuf == NULL) { 70 | int oerrno = errno; 71 | free(buf); 72 | errno = oerrno; 73 | buf = NULL; 74 | return NULL; 75 | } else 76 | buf = nbuf; 77 | 78 | *len = bufsiz; 79 | if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) 80 | return buf; 81 | 82 | bufsiz = nbufsiz; 83 | } 84 | 85 | *len = (ptr - buf) + 1; 86 | return buf; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /compat/forkpty-aix.c: -------------------------------------------------------------------------------- 1 | /* $Id: forkpty-aix.c,v 1.5 2011/01/10 22:45:09 nicm Exp $ */ 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: forkpty-hpux.c,v 1.1 2011/01/21 20:35:20 nicm Exp $ */ 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: forkpty-sunos.c,v 1.10 2011/01/10 22:45:10 nicm Exp $ */ 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: imsg.h,v 1.5 2010/06/06 00:08:28 tcunha Exp $ */ 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: setenv.c,v 1.2 2010/06/05 18:20:48 nicm Exp $ */ 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: strsep.c,v 1.2 2011/01/10 22:45:10 nicm Exp $ */ 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 | -------------------------------------------------------------------------------- /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 | bind 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_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: grid-utf8.c,v 1.2 2009/12/04 22:14:47 tcunha Exp $ */ 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 | -------------------------------------------------------------------------------- /names.c: -------------------------------------------------------------------------------- 1 | /* $Id: names.c,v 1.21 2009/12/04 22:14:47 tcunha Exp $ */ 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 | #include 25 | 26 | #include "tmux.h" 27 | 28 | void window_name_callback(unused int, unused short, void *); 29 | char *parse_window_name(const char *); 30 | 31 | void 32 | queue_window_name(struct window *w) 33 | { 34 | struct timeval tv; 35 | 36 | tv.tv_sec = 0; 37 | tv.tv_usec = NAME_INTERVAL * 1000L; 38 | 39 | evtimer_del(&w->name_timer); 40 | evtimer_set(&w->name_timer, window_name_callback, w); 41 | evtimer_add(&w->name_timer, &tv); 42 | } 43 | 44 | /* ARGSUSED */ 45 | void 46 | window_name_callback(unused int fd, unused short events, void *data) 47 | { 48 | struct window *w = data; 49 | char *name, *wname; 50 | 51 | queue_window_name(w); /* XXX even if the option is off? */ 52 | if (!options_get_number(&w->options, "automatic-rename")) 53 | return; 54 | 55 | if (w->active->screen != &w->active->base) 56 | name = NULL; 57 | else 58 | name = osdep_get_name(w->active->fd, w->active->tty); 59 | if (name == NULL) 60 | wname = default_window_name(w); 61 | else { 62 | /* 63 | * If tmux is using the default command, it will be a login 64 | * shell and argv[0] may have a - prefix. Remove this if it is 65 | * present. Ick. 66 | */ 67 | if (w->active->cmd != NULL && *w->active->cmd == '\0' && 68 | name != NULL && name[0] == '-' && name[1] != '\0') 69 | wname = parse_window_name(name + 1); 70 | else 71 | wname = parse_window_name(name); 72 | xfree(name); 73 | } 74 | 75 | if (w->active->fd == -1) { 76 | xasprintf(&name, "%s[dead]", wname); 77 | xfree(wname); 78 | wname = name; 79 | } 80 | 81 | if (strcmp(wname, w->name) == 0) 82 | xfree(wname); 83 | else { 84 | xfree(w->name); 85 | w->name = wname; 86 | server_status_window(w); 87 | } 88 | } 89 | 90 | char * 91 | default_window_name(struct window *w) 92 | { 93 | if (w->active->screen != &w->active->base) 94 | return (xstrdup("[tmux]")); 95 | if (w->active->cmd != NULL && *w->active->cmd != '\0') 96 | return (parse_window_name(w->active->cmd)); 97 | return (parse_window_name(w->active->shell)); 98 | } 99 | 100 | char * 101 | parse_window_name(const char *in) 102 | { 103 | char *copy, *name, *ptr; 104 | 105 | name = copy = xstrdup(in); 106 | if (strncmp(name, "exec ", (sizeof "exec ") - 1) == 0) 107 | name = name + (sizeof "exec ") - 1; 108 | 109 | while (*name == ' ') 110 | name++; 111 | if ((ptr = strchr(name, ' ')) != NULL) 112 | *ptr = '\0'; 113 | 114 | if (*name != '\0') { 115 | ptr = name + strlen(name) - 1; 116 | while (ptr > name && !isalnum((u_char)*ptr)) 117 | *ptr-- = '\0'; 118 | } 119 | 120 | if (*name == '/') 121 | name = basename(name); 122 | name = xstrdup(name); 123 | xfree(copy); 124 | return (name); 125 | } 126 | -------------------------------------------------------------------------------- /osdep-aix.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-aix.c,v 1.1 2011/01/10 22:00:47 nicm Exp $ */ 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 | struct event_base * 32 | osdep_event_init(void) 33 | { 34 | return (event_init()); 35 | } 36 | -------------------------------------------------------------------------------- /osdep-darwin.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-darwin.c,v 1.12 2010/12/30 20:41:07 nicm Exp $ */ 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 | 27 | char *osdep_get_name(int, char *); 28 | struct event_base *osdep_event_init(void); 29 | 30 | #define unused __attribute__ ((unused)) 31 | 32 | char * 33 | osdep_get_name(int fd, unused char *tty) 34 | { 35 | int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 }; 36 | size_t size; 37 | struct kinfo_proc kp; 38 | 39 | if ((mib[3] = tcgetpgrp(fd)) == -1) 40 | return (NULL); 41 | 42 | size = sizeof kp; 43 | if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1) 44 | return (NULL); 45 | if (*kp.kp_proc.p_comm == '\0') 46 | return (NULL); 47 | 48 | return (strdup(kp.kp_proc.p_comm)); 49 | } 50 | 51 | struct event_base * 52 | osdep_event_init(void) 53 | { 54 | /* 55 | * On OS X, kqueue and poll are both completely broken and don't 56 | * work on anything except socket file descriptors (yes, really). 57 | */ 58 | setenv("EVENT_NOKQUEUE", "1", 1); 59 | setenv("EVENT_NOPOLL", "1", 1); 60 | return (event_init()); 61 | } 62 | -------------------------------------------------------------------------------- /osdep-hpux.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-hpux.c,v 1.1 2011/01/21 20:35:20 nicm Exp $ */ 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 | struct event_base * 32 | osdep_event_init(void) 33 | { 34 | return (event_init()); 35 | } 36 | -------------------------------------------------------------------------------- /osdep-linux.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-linux.c,v 1.8 2011/01/13 19:58:47 nicm Exp $ */ 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 | xfree(path); 44 | return (NULL); 45 | } 46 | xfree(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 | struct event_base * 64 | osdep_event_init(void) 65 | { 66 | /* 67 | * On Linux, epoll doesn't work on /dev/null (yes, really). 68 | * 69 | * This has been commented because libevent versions up until the very 70 | * latest (1.4 git or 2.0.10) do not handle signals properly when using 71 | * poll or select, causing hangs. 72 | * 73 | */ 74 | /* setenv("EVENT_NOEPOLL", "1", 1); */ 75 | return (event_init()); 76 | } 77 | -------------------------------------------------------------------------------- /osdep-netbsd.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-netbsd.c,v 1.10 2010/12/30 20:41:08 nicm Exp $ */ 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 | 30 | #define is_runnable(p) \ 31 | ((p)->p_stat == LSRUN || (p)->p_stat == SIDL) 32 | #define is_stopped(p) \ 33 | ((p)->p_stat == SSTOP || (p)->p_stat == SZOMB) 34 | 35 | struct kinfo_proc2 *cmp_procs(struct kinfo_proc2 *, struct kinfo_proc2 *); 36 | char *osdep_get_name(int, char *); 37 | struct event_base *osdep_event_init(void); 38 | 39 | struct kinfo_proc2 * 40 | cmp_procs(struct kinfo_proc2 *p1, struct kinfo_proc2 *p2) 41 | { 42 | if (is_runnable(p1) && !is_runnable(p2)) 43 | return (p1); 44 | if (!is_runnable(p1) && is_runnable(p2)) 45 | return (p2); 46 | 47 | if (is_stopped(p1) && !is_stopped(p2)) 48 | return (p1); 49 | if (!is_stopped(p1) && is_stopped(p2)) 50 | return (p2); 51 | 52 | if (p1->p_estcpu > p2->p_estcpu) 53 | return (p1); 54 | if (p1->p_estcpu < p2->p_estcpu) 55 | return (p2); 56 | 57 | if (p1->p_slptime < p2->p_slptime) 58 | return (p1); 59 | if (p1->p_slptime > p2->p_slptime) 60 | return (p2); 61 | 62 | if (p1->p_pid > p2->p_pid) 63 | return (p1); 64 | return (p2); 65 | } 66 | 67 | char * 68 | osdep_get_name(int fd, __unused char *tty) 69 | { 70 | int mib[6]; 71 | struct stat sb; 72 | size_t len, i; 73 | struct kinfo_proc2 *buf, *newbuf, *bestp; 74 | char *name; 75 | 76 | if (stat(tty, &sb) == -1) 77 | return (NULL); 78 | if ((mib[3] = tcgetpgrp(fd)) == -1) 79 | return (NULL); 80 | 81 | buf = NULL; 82 | len = sizeof(bestp); 83 | mib[0] = CTL_KERN; 84 | mib[1] = KERN_PROC2; 85 | mib[2] = KERN_PROC_PGRP; 86 | mib[4] = sizeof (*buf); 87 | mib[5] = 0; 88 | 89 | retry: 90 | if (sysctl(mib, __arraycount(mib), NULL, &len, NULL, 0) == -1) 91 | return (NULL); 92 | 93 | if ((newbuf = realloc(buf, len * sizeof (*buf))) == NULL) 94 | goto error; 95 | buf = newbuf; 96 | 97 | mib[5] = len / sizeof(*buf); 98 | if (sysctl(mib, __arraycount(mib), buf, &len, NULL, 0) == -1) { 99 | if (errno == ENOMEM) 100 | goto retry; /* possible infinite loop? */ 101 | goto error; 102 | } 103 | 104 | bestp = NULL; 105 | for (i = 0; i < len / sizeof (*buf); i++) { 106 | if (buf[i].p_tdev != sb.st_rdev) 107 | continue; 108 | if (bestp == NULL) 109 | bestp = &buf[i]; 110 | else 111 | bestp = cmp_procs(&buf[i], bestp); 112 | } 113 | 114 | name = NULL; 115 | if (bestp != NULL) 116 | name = strdup(bestp->p_comm); 117 | 118 | free(buf); 119 | return (name); 120 | 121 | error: 122 | free(buf); 123 | return (NULL); 124 | } 125 | 126 | struct event_base * 127 | osdep_event_init(void) 128 | { 129 | return (event_init()); 130 | } 131 | -------------------------------------------------------------------------------- /osdep-sunos.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-sunos.c,v 1.3 2010/12/30 20:41:08 nicm Exp $ */ 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) || 45 | (ioctl(f, TIOCGPGRP, &pgrp) != 0)) { 46 | close(f); 47 | return (NULL); 48 | } 49 | close(f); 50 | 51 | xasprintf(&path, "/proc/%hu/psinfo", pgrp); 52 | f = open(path, O_RDONLY); 53 | xfree(path); 54 | if (f < 0) 55 | return (NULL); 56 | 57 | bytes = read(f, &p, sizeof(p)); 58 | close(f); 59 | if (bytes != sizeof(p)) 60 | return (NULL); 61 | 62 | if (p.pr_ttydev != st.st_rdev) 63 | return (NULL); 64 | 65 | return (xstrdup(p.pr_fname)); 66 | } 67 | 68 | struct event_base * 69 | osdep_event_init(void) 70 | { 71 | return (event_init()); 72 | } 73 | -------------------------------------------------------------------------------- /osdep-unknown.c: -------------------------------------------------------------------------------- 1 | /* $Id: osdep-unknown.c,v 1.6 2010/12/30 20:41:08 nicm Exp $ */ 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 | struct event_base * 32 | osdep_event_init(void) 33 | { 34 | return (event_init()); 35 | } 36 | -------------------------------------------------------------------------------- /signal.c: -------------------------------------------------------------------------------- 1 | /* $Id: signal.c,v 1.3 2010/08/29 14:42:11 tcunha Exp $ */ 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: check-compat.sh,v 1.1 2010/10/24 00:42:04 tcunha Exp $ 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: tty-acs.c,v 1.1 2010/09/18 15:43:53 tcunha Exp $ */ 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: window-clock.c,v 1.12 2010/05/22 21:56:04 micahcowan Exp $ */ 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 | struct screen *window_clock_init(struct window_pane *); 27 | void window_clock_free(struct window_pane *); 28 | void window_clock_resize(struct window_pane *, u_int, u_int); 29 | void window_clock_key(struct window_pane *, struct session *, int); 30 | void window_clock_timer(struct window_pane *); 31 | 32 | void window_clock_draw_screen(struct window_pane *); 33 | 34 | const struct window_mode window_clock_mode = { 35 | window_clock_init, 36 | window_clock_free, 37 | window_clock_resize, 38 | window_clock_key, 39 | NULL, 40 | window_clock_timer, 41 | }; 42 | 43 | struct window_clock_mode_data { 44 | struct screen screen; 45 | time_t tim; 46 | }; 47 | 48 | struct screen * 49 | window_clock_init(struct window_pane *wp) 50 | { 51 | struct window_clock_mode_data *data; 52 | struct screen *s; 53 | 54 | wp->modedata = data = xmalloc(sizeof *data); 55 | data->tim = time(NULL); 56 | 57 | s = &data->screen; 58 | screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0); 59 | s->mode &= ~MODE_CURSOR; 60 | 61 | window_clock_draw_screen(wp); 62 | 63 | return (s); 64 | } 65 | 66 | void 67 | window_clock_free(struct window_pane *wp) 68 | { 69 | struct window_clock_mode_data *data = wp->modedata; 70 | 71 | screen_free(&data->screen); 72 | xfree(data); 73 | } 74 | 75 | void 76 | window_clock_resize(struct window_pane *wp, u_int sx, u_int sy) 77 | { 78 | struct window_clock_mode_data *data = wp->modedata; 79 | struct screen *s = &data->screen; 80 | 81 | screen_resize(s, sx, sy); 82 | window_clock_draw_screen(wp); 83 | } 84 | 85 | /* ARGSUSED */ 86 | void 87 | window_clock_key( 88 | struct window_pane *wp, unused struct session *sess, unused int key) 89 | { 90 | window_pane_reset_mode(wp); 91 | } 92 | 93 | void 94 | window_clock_timer(struct window_pane *wp) 95 | { 96 | struct window_clock_mode_data *data = wp->modedata; 97 | struct tm now, then; 98 | time_t t; 99 | 100 | t = time(NULL); 101 | gmtime_r(&t, &now); 102 | gmtime_r(&data->tim, &then); 103 | if (now.tm_min == then.tm_min) 104 | return; 105 | data->tim = t; 106 | 107 | window_clock_draw_screen(wp); 108 | server_redraw_window(wp->window); 109 | } 110 | 111 | void 112 | window_clock_draw_screen(struct window_pane *wp) 113 | { 114 | struct window_clock_mode_data *data = wp->modedata; 115 | struct screen_write_ctx ctx; 116 | int colour, style; 117 | 118 | colour = options_get_number(&wp->window->options, "clock-mode-colour"); 119 | style = options_get_number(&wp->window->options, "clock-mode-style"); 120 | 121 | screen_write_start(&ctx, NULL, &data->screen); 122 | clock_draw(&ctx, colour, style); 123 | screen_write_stop(&ctx); 124 | } 125 | -------------------------------------------------------------------------------- /www/images/tmux3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThomasAdam/tmux-cvs-archived/bb461abad4bfdb5088de3ca362d9316cb387a93a/www/images/tmux3.png -------------------------------------------------------------------------------- /www/images/tmux4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThomasAdam/tmux-cvs-archived/bb461abad4bfdb5088de3ca362d9316cb387a93a/www/images/tmux4.png -------------------------------------------------------------------------------- /www/images/tmux5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThomasAdam/tmux-cvs-archived/bb461abad4bfdb5088de3ca362d9316cb387a93a/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: xmalloc.c,v 1.13 2010/09/07 19:32:58 nicm Exp $ */ 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 | void 86 | xfree(void *ptr) 87 | { 88 | if (ptr == NULL) 89 | fatalx("null pointer"); 90 | free(ptr); 91 | } 92 | 93 | int printflike2 94 | xasprintf(char **ret, const char *fmt, ...) 95 | { 96 | va_list ap; 97 | int i; 98 | 99 | va_start(ap, fmt); 100 | i = xvasprintf(ret, fmt, ap); 101 | va_end(ap); 102 | 103 | return (i); 104 | } 105 | 106 | int 107 | xvasprintf(char **ret, const char *fmt, va_list ap) 108 | { 109 | int i; 110 | 111 | i = vasprintf(ret, fmt, ap); 112 | if (i < 0 || *ret == NULL) 113 | fatal("xvasprintf failed"); 114 | 115 | return (i); 116 | } 117 | 118 | int printflike3 119 | xsnprintf(char *buf, size_t len, const char *fmt, ...) 120 | { 121 | va_list ap; 122 | int i; 123 | 124 | va_start(ap, fmt); 125 | i = xvsnprintf(buf, len, fmt, ap); 126 | va_end(ap); 127 | 128 | return (i); 129 | } 130 | 131 | int 132 | xvsnprintf(char *buf, size_t len, const char *fmt, va_list ap) 133 | { 134 | int i; 135 | 136 | if (len > INT_MAX) 137 | fatalx("len > INT_MAX"); 138 | 139 | i = vsnprintf(buf, len, fmt, ap); 140 | if (i < 0) 141 | fatal("vsnprintf failed"); 142 | 143 | return (i); 144 | } 145 | --------------------------------------------------------------------------------