mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
read: add commands to history
This commit is contained in:
parent
d613644edd
commit
8bfdb04630
1 changed files with 22 additions and 5 deletions
|
|
@ -6,15 +6,32 @@
|
||||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/02/06 14:11:37 by kcolin ### ########.fr */
|
/* Updated: 2025/02/06 14:19:04 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <readline/history.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
** get a command line using readline.
|
||||||
|
**
|
||||||
|
** returned buffer must be freed by caller.
|
||||||
|
** will add command to history if appropriate.
|
||||||
|
*/
|
||||||
|
static char *get_command(void)
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
line = readline("$ ");
|
||||||
|
if (line != NULL && line[0] != '\0')
|
||||||
|
add_history(line);
|
||||||
|
return (line);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[], char **envp)
|
int main(int argc, char *argv[], char **envp)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
|
@ -22,12 +39,12 @@ int main(int argc, char *argv[], char **envp)
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
(void)envp;
|
(void)envp;
|
||||||
line = readline("$ ");
|
line = get_command();
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
printf("%s", line); // FIXME
|
printf("%s\n", line); // FIXME
|
||||||
free(line);
|
free(line);
|
||||||
line = readline("$ ");
|
line = get_command();
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue