」 feat: prompt remake

This commit is contained in:
2024-04-30 12:36:16 +02:00
parent 51203c1a43
commit c91754dede

View File

@ -6,59 +6,88 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:34:52 by adjoly ### ########.fr */
/* Updated: 2024/04/29 13:35:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <readline/readline.h>
#include <readline/history.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <fcntl.h>
#include "minishell.h"
#include "libft.h"
t_boolean is_str(char *src, char *dst)
bool is_str(char *src, char *dst)
{
while (*src && *dst && *src == *dst)
{
src++;
dst++;
}
if (*src)
return (FALSE);
return (TRUE);
if (*dst)
return (false);
return (true);
}
void get_prompt(void)
char *get_hostname(void)
{
char *pwd;
char *hostname;
char *tmp;
int host_file;
host_file = open();
read();
tmp = hostname;
while (*tmp)
tmp++;
return
}
char *get_prompt(void)
{
char **prompt;
char *ret;
char *home;
char *user;
char *host;
char **tmp;
pwd = getenv("PWD");
prompt = malloc(1000);
prompt[0] = getenv("USER");
prompt[1] = "@";
prompt[2] = get_hostname();
home = getenv("HOME");
host = getenv("HOST");
user = getenv("USER");
prompt[3] = getenv("PWD");
prompt[4] = ">";
ret = ft_calloc(1000, sizeof(char));
if (!ft_strncmp(pwd, home, ft_strlen(home)))
if (!ft_strncmp(prompt[3], home, ft_strlen(home)))
prompt[3] += ft_strlen(home);
tmp = prompt;
while (*tmp)
{
ft_printf("%s@%s:~%s> ", user, host, pwd + ft_strlen(home));
return ;
ft_strlcat(ret, *tmp, ft_strlen(ret) + ft_strlen(*tmp) + 1);
tmp++;
}
ft_printf("%s@%s:%s> ", user, host, pwd);
free(prompt);
return (ret);
}
int main(int ac, char **av, char **env)
{
char *test;
char **lll;
char *ret;
(void)ac;
(void)av;
(void)env;
while (1)
{
get_prompt();
test = readline(NULL);
ret = get_prompt();
test = readline(ret);
free(ret);
add_history(test);
lll = ft_split(test, ' ');
if (!*lll)
continue;