Skip to content

Commit 2a2072b

Browse files
author
R E D O N E
authored
Merge pull request #44 from rick-morty-kh/Enhacement
skip spaces in history
2 parents 0859354 + 1b44725 commit 2a2072b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

execution/shell.c

+26-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
/* ::: :::::::: */
44
/* shell.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: relkabou <relkabou@student.42.fr> +#+ +:+ +#+ */
6+
/* By: relkabou <relkabou@student.1337.ma> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/02/01 00:04:46 by relkabou #+# #+# */
9-
/* Updated: 2023/02/05 16:52:03 by relkabou ### ########.fr */
9+
/* Updated: 2023/02/10 12:27:49 by relkabou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "minishell.h"
1414

15+
static int is_space(char c);
16+
static void ft_add_history(char *line);
17+
1518
void shell_loop(void)
1619
{
1720
char *line;
@@ -23,7 +26,7 @@ void shell_loop(void)
2326
line = readline(PROMPT);
2427
if (!line)
2528
break ;
26-
add_history(line);
29+
ft_add_history(line);
2730
cmd = parse_line(line);
2831
if (g_global.heredoc_flag)
2932
{
@@ -38,3 +41,23 @@ void shell_loop(void)
3841
free(line);
3942
}
4043
}
44+
45+
static void ft_add_history(char *line)
46+
{
47+
char *ptr;
48+
49+
ptr = line;
50+
if (!line)
51+
return ;
52+
while (*line && is_space(*line))
53+
{
54+
line++;
55+
}
56+
if (*line != 0)
57+
add_history(ptr);
58+
}
59+
60+
static int is_space(char c)
61+
{
62+
return (c == ' ' || (c >= '\t' && c <= '\r'));
63+
}

0 commit comments

Comments
 (0)