diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-08-08 13:22:49 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-08-08 13:22:49 +0000 |
commit | aa265bd00546d9ebfb6a04dd18e957052d87896f (patch) | |
tree | cae3dee1afc1b0f162ff74e2825355d9c769eec5 /usr.bin/ssh/sftp.c | |
parent | 6d62d435e16559ffe2c0358f17744110574379e6 (diff) |
sftp prompt enhancements:
- in non-interactive mode, do not print an empty prompt at the end
before finishing
- print newline after EOF in editline mode
- call el_end() in editline mode
ok dtucker djm
Diffstat (limited to 'usr.bin/ssh/sftp.c')
-rw-r--r-- | usr.bin/ssh/sftp.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c index ce5092862b7..d0070a1d1af 100644 --- a/usr.bin/ssh/sftp.c +++ b/usr.bin/ssh/sftp.c @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.65 2005/07/17 07:17:55 djm Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.66 2005/08/08 13:22:48 jaredy Exp $"); #include <glob.h> #include <histedit.h> @@ -1230,7 +1230,7 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) char *dir = NULL; char cmd[2048]; struct sftp_conn *conn; - int err; + int err, interactive; EditLine *el = NULL; History *hl = NULL; HistEvent hev; @@ -1289,6 +1289,7 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(infile, NULL, _IOLBF, 0); + interactive = !batchmode && isatty(STDIN_FILENO); err = 0; for (;;) { char *cp; @@ -1298,16 +1299,24 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) signal(SIGINT, SIG_IGN); if (el == NULL) { - printf("sftp> "); + if (interactive) + printf("sftp> "); if (fgets(cmd, sizeof(cmd), infile) == NULL) { - printf("\n"); + if (interactive) + printf("\n"); break; } - if (batchmode) /* Echo command */ - printf("%s", cmd); + if (!interactive) { /* Echo command */ + printf("sftp> %s", cmd); + if (strlen(cmd) > 0 && + cmd[strlen(cmd) - 1] != '\n') + printf("\n"); + } } else { - if ((line = el_gets(el, &count)) == NULL || count <= 0) + if ((line = el_gets(el, &count)) == NULL || count <= 0) { + printf("\n"); break; + } history(hl, &hev, H_ENTER, line); if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { fprintf(stderr, "Error: input line too long\n"); @@ -1329,6 +1338,9 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) } xfree(pwd); + if (el != NULL) + el_end(el); + /* err == 1 signifies normal "quit" exit */ return (err >= 0 ? 0 : -1); } |