summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2004-11-05 12:19:57 +0000
committerDamien Miller <djm@cvs.openbsd.org>2004-11-05 12:19:57 +0000
commit8b5ed39a7f8dac71c1eb09c99c6e824b529982c6 (patch)
tree5e491da0ed2f9886dcd97b7cf3dfcb06e75f3d82 /usr.bin/ssh
parent65224a876a1e9bc53d3eb19d3a4c7957e2e35e51 (diff)
command editing and history support via libedit; ok markus@
thanks to hshoexer@ and many testers on tech@ too
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/sftp.c55
-rw-r--r--usr.bin/ssh/sftp/Makefile5
2 files changed, 47 insertions, 13 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c
index d0e11979b23..959931cf131 100644
--- a/usr.bin/ssh/sftp.c
+++ b/usr.bin/ssh/sftp.c
@@ -16,9 +16,10 @@
#include "includes.h"
-RCSID("$OpenBSD: sftp.c,v 1.56 2004/07/11 17:48:47 deraadt Exp $");
+RCSID("$OpenBSD: sftp.c,v 1.57 2004/11/05 12:19:56 djm Exp $");
#include <glob.h>
+#include <histedit.h>
#include "buffer.h"
#include "xmalloc.h"
@@ -1206,6 +1207,12 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
return (0);
}
+static char *
+prompt(EditLine *el)
+{
+ return ("sftp> ");
+}
+
int
interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
{
@@ -1214,6 +1221,25 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
char cmd[2048];
struct sftp_conn *conn;
int err;
+ EditLine *el = NULL;
+ History *hl = NULL;
+ HistEvent hev;
+ extern char *__progname;
+
+ if (!batchmode && isatty(STDIN_FILENO)) {
+ if ((el = el_init(__progname, stdin, stdout, stderr)) == NULL)
+ fatal("Couldn't initialise editline");
+ if ((hl = history_init()) == NULL)
+ fatal("Couldn't initialise editline history");
+ history(hl, &hev, H_SETSIZE, 100);
+ el_set(el, EL_HIST, history, hl);
+
+ el_set(el, EL_PROMPT, prompt);
+ el_set(el, EL_EDITOR, "emacs");
+ el_set(el, EL_TERMINAL, NULL);
+ el_set(el, EL_SIGNAL, 1);
+ el_source(el, NULL);
+ }
conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests);
if (conn == NULL)
@@ -1253,20 +1279,29 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
err = 0;
for (;;) {
char *cp;
+ const char *line;
+ int count = 0;
signal(SIGINT, SIG_IGN);
- printf("sftp> ");
-
- /* XXX: use libedit */
- if (fgets(cmd, sizeof(cmd), infile) == NULL) {
- printf("\n");
- break;
+ if (el == NULL) {
+ printf("sftp> ");
+ if (fgets(cmd, sizeof(cmd), infile) == NULL) {
+ printf("\n");
+ break;
+ }
+ if (batchmode) /* Echo command */
+ printf("%s", cmd);
+ } else {
+ if ((line = el_gets(el, &count)) == NULL || count <= 0)
+ break;
+ history(hl, &hev, H_ENTER, line);
+ if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) {
+ fprintf(stderr, "Error: input line too long\n");
+ continue;
+ }
}
- if (batchmode) /* Echo command */
- printf("%s", cmd);
-
cp = strrchr(cmd, '\n');
if (cp)
*cp = '\0';
diff --git a/usr.bin/ssh/sftp/Makefile b/usr.bin/ssh/sftp/Makefile
index 6b97524652e..4c59efb086d 100644
--- a/usr.bin/ssh/sftp/Makefile
+++ b/usr.bin/ssh/sftp/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.8 2004/02/17 11:03:08 djm Exp $
+# $OpenBSD: Makefile,v 1.9 2004/11/05 12:19:56 djm Exp $
.PATH: ${.CURDIR}/..
@@ -14,6 +14,5 @@ SRCS= sftp.c sftp-client.c sftp-common.c sftp-glob.c
.include <bsd.prog.mk>
-LDADD+= -lcrypto
+LDADD+= -lcrypto -ledit -ltermcap
DPADD+= ${LIBCRYPTO}
-