mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
New command, send-keys, to send a set of keys.
This commit is contained in:
parent
99fa60f295
commit
65f4284e7f
6
CHANGES
6
CHANGES
@ -1,3 +1,7 @@
|
|||||||
|
01 June 2008
|
||||||
|
|
||||||
|
* New command, send-keys, will send a set of keys to a window.
|
||||||
|
|
||||||
31 May 2008
|
31 May 2008
|
||||||
|
|
||||||
* Fix so tmux doesn't hang if the initial window fails for some reason. This
|
* Fix so tmux doesn't hang if the initial window fails for some reason. This
|
||||||
@ -310,4 +314,4 @@
|
|||||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||||
customisation.
|
customisation.
|
||||||
|
|
||||||
$Id: CHANGES,v 1.94 2008-05-31 20:04:15 nicm Exp $
|
$Id: CHANGES,v 1.95 2008-06-01 20:20:25 nicm Exp $
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# $Id: GNUmakefile,v 1.11 2008-02-10 19:46:17 nicm Exp $
|
# $Id: GNUmakefile,v 1.12 2008-06-01 20:20:25 nicm Exp $
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
|
|||||||
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
|
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
|
||||||
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
|
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
|
||||||
cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \
|
cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \
|
||||||
cmd-link-window.c cmd-unlink-window.c cmd-next-window.c \
|
cmd-link-window.c cmd-unlink-window.c cmd-next-window.c cmd-send-keys.c \
|
||||||
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
|
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
|
||||||
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
|
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
|
||||||
cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \
|
cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \
|
||||||
|
4
Makefile
4
Makefile
@ -1,4 +1,4 @@
|
|||||||
# $Id: Makefile,v 1.52 2007-12-06 09:46:21 nicm Exp $
|
# $Id: Makefile,v 1.53 2008-06-01 20:20:25 nicm Exp $
|
||||||
|
|
||||||
.SUFFIXES: .c .o .y .h
|
.SUFFIXES: .c .o .y .h
|
||||||
.PHONY: clean update-index.html upload-index.html
|
.PHONY: clean update-index.html upload-index.html
|
||||||
@ -24,7 +24,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
|
|||||||
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
|
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
|
||||||
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
|
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
|
||||||
cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \
|
cmd-refresh-client.c cmd-kill-window.c cmd-list-clients.c \
|
||||||
cmd-link-window.c cmd-unlink-window.c cmd-next-window.c \
|
cmd-link-window.c cmd-unlink-window.c cmd-next-window.c cmd-send-keys.c \
|
||||||
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
|
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
|
||||||
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
|
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
|
||||||
cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \
|
cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \
|
||||||
|
8
TODO
8
TODO
@ -34,15 +34,12 @@
|
|||||||
kill server
|
kill server
|
||||||
show-options command
|
show-options command
|
||||||
command to run something without a window at all?
|
command to run something without a window at all?
|
||||||
command to insert a key into a window (send-key)
|
|
||||||
should paste-buffer become send-buffer.....
|
|
||||||
command to insert any data (a string) into a window (paste-data?)
|
|
||||||
command to purge window history
|
command to purge window history
|
||||||
extend list-clients to list clients attached to a session (-a for all?)
|
extend list-clients to list clients attached to a session (-a for all?)
|
||||||
bring back detach-session to detach all clients on a session?
|
bring back detach-session to detach all clients on a session?
|
||||||
paste buffer etc shouldn't be limited to keys
|
paste buffer etc shouldn't be limited to keys
|
||||||
buffer manip: clear, view etc (clear-buffer, show-buffer)
|
buffer manip: clear, view etc (clear-buffer, show-buffer)
|
||||||
- function groups, bind-key ^W { select-window 0; send-key ^W } etc
|
- function groups, bind-key ^W { select-window 0; send-key ^W } etc ***
|
||||||
- allow fnmatch for -c, so that you can, eg, detach all clients
|
- allow fnmatch for -c, so that you can, eg, detach all clients
|
||||||
- session specification is all over the place. some things use -s before cmd,
|
- session specification is all over the place. some things use -s before cmd,
|
||||||
some -s after, some no -s, there are various uses of -n. the differences are
|
some -s after, some no -s, there are various uses of -n. the differences are
|
||||||
@ -51,7 +48,7 @@
|
|||||||
- bind non prefix keys
|
- bind non prefix keys
|
||||||
- stuff like rename would be nice to be able to do in-client like screen, if
|
- stuff like rename would be nice to be able to do in-client like screen, if
|
||||||
it could be implemented in a non-icky way
|
it could be implemented in a non-icky way
|
||||||
- there is to much redrawing. use flags?
|
- there is too much redrawing. use flags?
|
||||||
- command mode (! + type tmux command)
|
- command mode (! + type tmux command)
|
||||||
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||||
in $x time (need window creation/use times)
|
in $x time (need window creation/use times)
|
||||||
@ -78,4 +75,3 @@
|
|||||||
- anything which uses cmd_{send,recv}_string will break if the string is
|
- anything which uses cmd_{send,recv}_string will break if the string is
|
||||||
split. string length should be part of the command size
|
split. string length should be part of the command size
|
||||||
- chmod +x socket when any client is attached (upd in lost/accept)
|
- chmod +x socket when any client is attached (upd in lost/accept)
|
||||||
|
|
||||||
|
143
cmd-send-keys.c
Normal file
143
cmd-send-keys.c
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/* $Id: cmd-send-keys.c,v 1.1 2008-06-01 20:20:25 nicm Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Change session name.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cmd_send_keys_parse(void **, int, char **, char **);
|
||||||
|
void cmd_send_keys_exec(void *, struct cmd_ctx *);
|
||||||
|
void cmd_send_keys_send(void *, struct buffer *);
|
||||||
|
void cmd_send_keys_recv(void **, struct buffer *);
|
||||||
|
void cmd_send_keys_free(void *);
|
||||||
|
|
||||||
|
struct cmd_send_keys_data {
|
||||||
|
u_int nkeys;
|
||||||
|
int *keys;
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct cmd_entry cmd_send_keys_entry = {
|
||||||
|
"send-keys", "send", "key ...",
|
||||||
|
0,
|
||||||
|
cmd_send_keys_parse,
|
||||||
|
cmd_send_keys_exec,
|
||||||
|
cmd_send_keys_send,
|
||||||
|
cmd_send_keys_recv,
|
||||||
|
cmd_send_keys_free
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
cmd_send_keys_parse(void **ptr, int argc, char **argv, char **cause)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data;
|
||||||
|
int opt, key;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
*ptr = data = xmalloc(sizeof *data);
|
||||||
|
data->nkeys = 0;
|
||||||
|
data->keys = NULL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "")) != EOF) {
|
||||||
|
switch (opt) {
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc == 0)
|
||||||
|
goto usage;
|
||||||
|
|
||||||
|
while (argc-- != 0) {
|
||||||
|
if ((key = key_string_lookup_string(*argv)) != KEYC_NONE) {
|
||||||
|
data->keys = xrealloc(
|
||||||
|
data->keys, data->nkeys + 1, sizeof *data->keys);
|
||||||
|
data->keys[data->nkeys++] = key;
|
||||||
|
} else {
|
||||||
|
for (s = *argv; *s != '\0'; s++) {
|
||||||
|
data->keys = xrealloc(data->keys,
|
||||||
|
data->nkeys + 1, sizeof *data->keys);
|
||||||
|
data->keys[data->nkeys++] = *s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
usage:
|
||||||
|
usage(cause, "%s %s",
|
||||||
|
cmd_send_keys_entry.name, cmd_send_keys_entry.usage);
|
||||||
|
|
||||||
|
cmd_send_keys_free(data);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_send_keys_exec(void *ptr, struct cmd_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = ptr;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < data->nkeys; i++)
|
||||||
|
window_key(ctx->client->session->curw->window, data->keys[i]);
|
||||||
|
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_send_keys_send(void *ptr, struct buffer *b)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = ptr;
|
||||||
|
|
||||||
|
buffer_write(b, data, sizeof *data);
|
||||||
|
buffer_write(b, data->keys, data->nkeys * sizeof *data->keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_send_keys_recv(void **ptr, struct buffer *b)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data;
|
||||||
|
|
||||||
|
*ptr = data = xmalloc(sizeof *data);
|
||||||
|
buffer_read(b, data, sizeof *data);
|
||||||
|
data->keys = xcalloc(data->nkeys, sizeof *data->keys);
|
||||||
|
buffer_read(b, data->keys, data->nkeys * sizeof *data->keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmd_send_keys_free(void *ptr)
|
||||||
|
{
|
||||||
|
struct cmd_send_keys_data *data = ptr;
|
||||||
|
|
||||||
|
if (data->keys != NULL)
|
||||||
|
xfree(data->keys);
|
||||||
|
xfree(data);
|
||||||
|
}
|
3
cmd.c
3
cmd.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd.c,v 1.33 2007-12-06 09:46:22 nicm Exp $ */
|
/* $Id: cmd.c,v 1.34 2008-06-01 20:20:25 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -47,6 +47,7 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
&cmd_rename_window_entry,
|
&cmd_rename_window_entry,
|
||||||
&cmd_scroll_mode_entry,
|
&cmd_scroll_mode_entry,
|
||||||
&cmd_select_window_entry,
|
&cmd_select_window_entry,
|
||||||
|
&cmd_send_keys_entry,
|
||||||
&cmd_send_prefix_entry,
|
&cmd_send_prefix_entry,
|
||||||
&cmd_set_option_entry,
|
&cmd_set_option_entry,
|
||||||
&cmd_swap_window_entry,
|
&cmd_swap_window_entry,
|
||||||
|
14
tmux.1
14
tmux.1
@ -1,4 +1,4 @@
|
|||||||
.\" $Id: tmux.1,v 1.23 2008-05-31 23:08:48 nicm Exp $
|
.\" $Id: tmux.1,v 1.24 2008-06-01 20:20:25 nicm Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
.\"
|
.\"
|
||||||
@ -421,6 +421,18 @@ This command works only if bound to a key.
|
|||||||
.D1 (alias: Ic selectw )
|
.D1 (alias: Ic selectw )
|
||||||
Select the window at
|
Select the window at
|
||||||
.Ar index .
|
.Ar index .
|
||||||
|
.It Xo Ic send-keys Ar key Ar ...
|
||||||
|
.Xc
|
||||||
|
Send a key or keys to a window.
|
||||||
|
Each argument
|
||||||
|
.Ar key
|
||||||
|
is the name of the key (such as
|
||||||
|
.Ql ^A
|
||||||
|
or
|
||||||
|
.Ql npage
|
||||||
|
) to send; if the string is not recognised as a key, it is sent as a series of
|
||||||
|
characters.
|
||||||
|
All the arguments are sent sequentially from first to last.
|
||||||
.It Xo Ic send-prefix
|
.It Xo Ic send-prefix
|
||||||
.Xc
|
.Xc
|
||||||
Send the prefix key to a window as if it was pressed.
|
Send the prefix key to a window as if it was pressed.
|
||||||
|
3
tmux.h
3
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.115 2008-05-31 18:04:57 nicm Exp $ */
|
/* $Id: tmux.h,v 1.116 2008-06-01 20:20:25 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -748,6 +748,7 @@ extern const struct cmd_entry cmd_rename_session_entry;
|
|||||||
extern const struct cmd_entry cmd_rename_window_entry;
|
extern const struct cmd_entry cmd_rename_window_entry;
|
||||||
extern const struct cmd_entry cmd_scroll_mode_entry;
|
extern const struct cmd_entry cmd_scroll_mode_entry;
|
||||||
extern const struct cmd_entry cmd_select_window_entry;
|
extern const struct cmd_entry cmd_select_window_entry;
|
||||||
|
extern const struct cmd_entry cmd_send_keys_entry;
|
||||||
extern const struct cmd_entry cmd_send_prefix_entry;
|
extern const struct cmd_entry cmd_send_prefix_entry;
|
||||||
extern const struct cmd_entry cmd_set_option_entry;
|
extern const struct cmd_entry cmd_set_option_entry;
|
||||||
extern const struct cmd_entry cmd_swap_window_entry;
|
extern const struct cmd_entry cmd_swap_window_entry;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user