mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「✨」 feat: Prompt finished
This commit is contained in:
@ -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
libft/libft.a
Normal file
BIN
libft/libft.a
Normal file
Binary file not shown.
BIN
libft/src/char/ft_isalnum.o
Normal file
BIN
libft/src/char/ft_isalnum.o
Normal file
Binary file not shown.
BIN
libft/src/char/ft_isalpha.o
Normal file
BIN
libft/src/char/ft_isalpha.o
Normal file
Binary file not shown.
BIN
libft/src/char/ft_isascii.o
Normal file
BIN
libft/src/char/ft_isascii.o
Normal file
Binary file not shown.
BIN
libft/src/char/ft_isdigit.o
Normal file
BIN
libft/src/char/ft_isdigit.o
Normal file
Binary file not shown.
BIN
libft/src/char/ft_isprint.o
Normal file
BIN
libft/src/char/ft_isprint.o
Normal file
Binary file not shown.
BIN
libft/src/int/ft_abs.o
Normal file
BIN
libft/src/int/ft_abs.o
Normal file
Binary file not shown.
BIN
libft/src/int/ft_max.o
Normal file
BIN
libft/src/int/ft_max.o
Normal file
Binary file not shown.
BIN
libft/src/int/ft_min.o
Normal file
BIN
libft/src/int/ft_min.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_printf.o
Normal file
BIN
libft/src/io/ft_printf.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_printf_fd.o
Normal file
BIN
libft/src/io/ft_printf_fd.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_putchar_fd.o
Normal file
BIN
libft/src/io/ft_putchar_fd.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_putendl_fd.o
Normal file
BIN
libft/src/io/ft_putendl_fd.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_putnbr_fd.o
Normal file
BIN
libft/src/io/ft_putnbr_fd.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_putstr_fd.o
Normal file
BIN
libft/src/io/ft_putstr_fd.o
Normal file
Binary file not shown.
BIN
libft/src/io/ft_putuhex_fd.o
Normal file
BIN
libft/src/io/ft_putuhex_fd.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstadd_back.o
Normal file
BIN
libft/src/linked_lists/ft_lstadd_back.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstadd_front.o
Normal file
BIN
libft/src/linked_lists/ft_lstadd_front.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstclear.o
Normal file
BIN
libft/src/linked_lists/ft_lstclear.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstdelone.o
Normal file
BIN
libft/src/linked_lists/ft_lstdelone.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstiter.o
Normal file
BIN
libft/src/linked_lists/ft_lstiter.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstlast.o
Normal file
BIN
libft/src/linked_lists/ft_lstlast.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstmap.o
Normal file
BIN
libft/src/linked_lists/ft_lstmap.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstnew.o
Normal file
BIN
libft/src/linked_lists/ft_lstnew.o
Normal file
Binary file not shown.
BIN
libft/src/linked_lists/ft_lstsize.o
Normal file
BIN
libft/src/linked_lists/ft_lstsize.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_bzero.o
Normal file
BIN
libft/src/mem/ft_bzero.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_calloc.o
Normal file
BIN
libft/src/mem/ft_calloc.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_free.o
Normal file
BIN
libft/src/mem/ft_free.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_memchr.o
Normal file
BIN
libft/src/mem/ft_memchr.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_memcmp.o
Normal file
BIN
libft/src/mem/ft_memcmp.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_memcpy.o
Normal file
BIN
libft/src/mem/ft_memcpy.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_memmove.o
Normal file
BIN
libft/src/mem/ft_memmove.o
Normal file
Binary file not shown.
BIN
libft/src/mem/ft_memset.o
Normal file
BIN
libft/src/mem/ft_memset.o
Normal file
Binary file not shown.
BIN
libft/src/stack/ft_stackadd_back.o
Normal file
BIN
libft/src/stack/ft_stackadd_back.o
Normal file
Binary file not shown.
BIN
libft/src/stack/ft_stackadd_front.o
Normal file
BIN
libft/src/stack/ft_stackadd_front.o
Normal file
Binary file not shown.
BIN
libft/src/stack/ft_stacklast.o
Normal file
BIN
libft/src/stack/ft_stacklast.o
Normal file
Binary file not shown.
BIN
libft/src/stack/ft_stacknew.o
Normal file
BIN
libft/src/stack/ft_stacknew.o
Normal file
Binary file not shown.
BIN
libft/src/stack/ft_stacksize.o
Normal file
BIN
libft/src/stack/ft_stacksize.o
Normal file
Binary file not shown.
BIN
libft/src/str/XtoX/ft_atoi.o
Normal file
BIN
libft/src/str/XtoX/ft_atoi.o
Normal file
Binary file not shown.
BIN
libft/src/str/XtoX/ft_atol.o
Normal file
BIN
libft/src/str/XtoX/ft_atol.o
Normal file
Binary file not shown.
BIN
libft/src/str/XtoX/ft_itoa.o
Normal file
BIN
libft/src/str/XtoX/ft_itoa.o
Normal file
Binary file not shown.
BIN
libft/src/str/XtoX/ft_ltoa.o
Normal file
BIN
libft/src/str/XtoX/ft_ltoa.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_split.o
Normal file
BIN
libft/src/str/ft_split.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strchr.o
Normal file
BIN
libft/src/str/ft_strchr.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strcmp.o
Normal file
BIN
libft/src/str/ft_strcmp.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strdup.o
Normal file
BIN
libft/src/str/ft_strdup.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_striteri.o
Normal file
BIN
libft/src/str/ft_striteri.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strjoin.o
Normal file
BIN
libft/src/str/ft_strjoin.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strlcat.o
Normal file
BIN
libft/src/str/ft_strlcat.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strlcpy.o
Normal file
BIN
libft/src/str/ft_strlcpy.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strlen.o
Normal file
BIN
libft/src/str/ft_strlen.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strmapi.o
Normal file
BIN
libft/src/str/ft_strmapi.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strncmp.o
Normal file
BIN
libft/src/str/ft_strncmp.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strnstr.o
Normal file
BIN
libft/src/str/ft_strnstr.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strrchr.o
Normal file
BIN
libft/src/str/ft_strrchr.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_strtrim.o
Normal file
BIN
libft/src/str/ft_strtrim.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_substr.o
Normal file
BIN
libft/src/str/ft_substr.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_tolower.o
Normal file
BIN
libft/src/str/ft_tolower.o
Normal file
Binary file not shown.
BIN
libft/src/str/ft_toupper.o
Normal file
BIN
libft/src/str/ft_toupper.o
Normal file
Binary file not shown.
BIN
obj/src/env_cmd.o
Normal file
BIN
obj/src/env_cmd.o
Normal file
Binary file not shown.
BIN
obj/src/main.o
Normal file
BIN
obj/src/main.o
Normal file
Binary file not shown.
BIN
obj/src/prompt/get_hostname.o
Normal file
BIN
obj/src/prompt/get_hostname.o
Normal file
Binary file not shown.
BIN
obj/src/prompt/get_prompt.o
Normal file
BIN
obj/src/prompt/get_prompt.o
Normal file
Binary file not shown.
BIN
obj/src/prompt/get_pwd.o
Normal file
BIN
obj/src/prompt/get_pwd.o
Normal file
Binary file not shown.
52
src/main.c
52
src/main.c
@ -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
src/prompt/get_hostname.c
Normal file
36
src/prompt/get_hostname.c
Normal 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);
|
||||||
|
}
|
@ -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
src/prompt/get_pwd.c
Normal file
27
src/prompt/get_pwd.c
Normal 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);
|
||||||
|
}
|
Reference in New Issue
Block a user