From 1b447253bba28d0572149a1f7eb5590558985afa Mon Sep 17 00:00:00 2001 From: redouane Date: Fri, 10 Feb 2023 12:31:18 +0100 Subject: [PATCH] skip spaces in history --- execution/shell.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/execution/shell.c b/execution/shell.c index b80faae..8409e8a 100644 --- a/execution/shell.c +++ b/execution/shell.c @@ -3,15 +3,18 @@ /* ::: :::::::: */ /* shell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: relkabou +#+ +:+ +#+ */ +/* By: relkabou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/01 00:04:46 by relkabou #+# #+# */ -/* Updated: 2023/02/05 16:52:03 by relkabou ### ########.fr */ +/* Updated: 2023/02/10 12:27:49 by relkabou ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +static int is_space(char c); +static void ft_add_history(char *line); + void shell_loop(void) { char *line; @@ -23,7 +26,7 @@ void shell_loop(void) line = readline(PROMPT); if (!line) break ; - add_history(line); + ft_add_history(line); cmd = parse_line(line); if (g_global.heredoc_flag) { @@ -38,3 +41,23 @@ void shell_loop(void) free(line); } } + +static void ft_add_history(char *line) +{ + char *ptr; + + ptr = line; + if (!line) + return ; + while (*line && is_space(*line)) + { + line++; + } + if (*line != 0) + add_history(ptr); +} + +static int is_space(char c) +{ + return (c == ' ' || (c >= '\t' && c <= '\r')); +}