「✨」 feat: Prompt finished

This commit is contained in:
KeyZox committed 2024-05-02 15:50:58 +02:00
1 parent 272061eafc
commit bbadc3e663
71 files changed
+83 -86

No files matched your search

+4 -1
View File
@@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 09:38:51 by mmoussou #+# #+# */ /* Created: 2024/04/26 09:38:51 by mmoussou #+# #+# */
/* Updated: 2024/04/30 12:39:03 by adjoly ### ########.fr */ /* Updated: 2024/05/02 15:31:38 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -22,5 +22,8 @@
# include "libft.h" # include "libft.h"
char set_env(char **env, const char *name, char *content); char set_env(char **env, const char *name, char *content);
char *get_hostname(void);
char *get_prompt(void);
char *get_pwd(void);
#endif #endif
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View File
Whitespace-only changes.
+5 -47
View File
@@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */ /* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/04/30 12:40:35 by adjoly ### ########.fr */ /* Updated: 2024/05/02 15:47:34 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -30,61 +30,19 @@ bool is_str(char *src, char *dst)
return (true); return (true);
} }
/*char *get_hostname(void)
{
char *hostname;
char *tmp;
int host_file;
//host_file = open();
tmp = hostname;
while (*tmp)
tmp++;
return
}*/
char *get_prompt(void)
{
char **prompt;
char *ret = NULL;
char *home;
char **tmp;
prompt = malloc(1000);
prompt[0] = getenv("USER");
prompt[1] = "@";
//prompt[2] = get_hostname();
home = getenv("HOME");
prompt[3] = getenv("PWD");
prompt[4] = ">";
//ret = ft_calloc(1000, sizeof(char));
if (!ft_strncmp(prompt[3], home, ft_strlen(home)))
prompt[3] += ft_strlen(home);
tmp = prompt;
while (*tmp)
{
ft_strlcat(ret, *tmp, ft_strlen(ret) + ft_strlen(*tmp) + 1);
tmp++;
}
free(prompt);
return (ret);
}
int main(int ac, char **av, char **env) int main(int ac, char **av, char **env)
{ {
char *test; char *test;
char **lll; char **lll;
char *ret = NULL; char *prompt;
(void)ac; (void)ac;
(void)av; (void)av;
(void)env; (void)env;
while (1) while (1)
{ {
ret = get_prompt(); prompt = get_prompt();
test = readline(ret); test = readline(prompt);
free(ret);
add_history(test); add_history(test);
lll = ft_split(test, ' '); lll = ft_split(test, ' ');
if (!*lll) if (!*lll)
@@ -92,6 +50,6 @@ int main(int ac, char **av, char **env)
if (is_str(test, "exit")) if (is_str(test, "exit"))
break; break;
} }
//ft_freearr((void **)lll); //ft_free("a", &lll);
return (0); return (0);
} }
+36
View File
@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_hostname.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */
/* Updated: 2024/05/02 13:42:24 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "fcntl.h"
#include "libft.h"
char *get_hostname(void)
{
char *hostname;
char *buf;
int host_file;
char *delimiter;
buf = ft_calloc(254, sizeof(char));
host_file = open("/etc/hostname", O_RDONLY);
read(host_file, buf, 254);
delimiter = ft_strchr(buf, '.');
if (!delimiter)
{
free(buf);
return (buf);
}
hostname = ft_calloc(delimiter - buf, sizeof(char));
ft_strlcpy(hostname, buf, delimiter - buf + 1);
free(buf);
return (hostname);
}
+11 -38
View File
@@ -6,49 +6,22 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */ /* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */
/* Updated: 2024/04/30 13:27:03 by adjoly ### ########.fr */ /* Updated: 2024/05/02 15:50:14 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
/*char *get_hostname(void) #include "libft.h"
{ #include "minishell.h"
char *hostname;
char *tmp;
int host_file;
//host_file = open();
tmp = hostname;
while (*tmp)
tmp++;
return
}*/
char *get_prompt(void) char *get_prompt(void)
{ {
char **prompt; char *prompt;
char *ret = NULL;
char *home;
char **tmp;
prompt = malloc(1000); prompt = getenv("USER");
prompt[0] = getenv("USER"); prompt = ft_strjoin(prompt, "@");
prompt[1] = "@"; prompt = ft_strjoin_free(prompt, get_hostname());
//prompt[2] = get_hostname(); prompt = ft_strjoin_free_s1(prompt, ":");
home = getenv("HOME"); prompt = ft_strjoin_free(prompt, get_pwd());
prompt[3] = getenv("PWD"); prompt = ft_strjoin_free_s1(prompt, "$ ");
prompt[4] = ">"; return (prompt);
//ret = ft_calloc(1000, sizeof(char));
if (!ft_strncmp(prompt[3], home, ft_strlen(home)))
prompt[3] += ft_strlen(home);
tmp = prompt;
while (*tmp)
{
ft_strlcat(ret, *tmp, ft_strlen(ret) + ft_strlen(*tmp) + 1);
tmp++;
} }
free(prompt);
return (ret);
}
+27
View File
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */
/* Updated: 2024/05/02 15:49:42 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *get_pwd(void)
{
char *pwd;
char *home;
pwd = getenv("PWD");
home = getenv("HOME");
if (!ft_strncmp(pwd, home, ft_strlen(home)))
pwd += ft_strlen(home);
pwd = ft_strjoin("~", pwd);
return (pwd);
}