From 25fab4cb2ef20140d2b2ac484e9ef6aa8171390a Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Fri, 23 Jul 2021 23:46:20 +0530 Subject: [PATCH] Open controlling terminal for input when run in a script --- src/nnn.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nnn.c b/src/nnn.c index 6e447e0e..2fc1039d 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -8225,7 +8225,13 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; /* We return to tty */ - dup2(STDOUT_FILENO, STDIN_FILENO); + if (!isatty(STDOUT_FILENO)) { + fd = open(ctermid(NULL), O_RDWR, 0400); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDIN_FILENO); + close(fd); + } else + dup2(STDOUT_FILENO, STDIN_FILENO); if (session) session = NULL;