From 6aabe49df14769d43a94697b4d03f5962d626b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Thu, 6 Feb 2025 14:24:17 +0100 Subject: [PATCH] read: do not display prompt if not in a tty --- src/minishell.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/minishell.c b/src/minishell.c index 5941a44..e7a4ae1 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ -/* Updated: 2025/02/06 14:19:04 by kcolin ### ########.fr */ +/* Updated: 2025/02/06 14:25:02 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,19 @@ #include #include #include +#include + +/* +** get the prompt to show to the user when getting a command +** +** if the terminal is a tty, the prompt is '$ ', else it is '' +*/ +static const char *get_prompt(void) +{ + if (isatty(STDIN_FILENO)) + return ("$ "); + return (""); +} /* ** get a command line using readline. @@ -26,7 +39,7 @@ static char *get_command(void) { char *line; - line = readline("$ "); + line = readline(get_prompt()); if (line != NULL && line[0] != '\0') add_history(line); return (line);