mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2026-11-27 13:54:52 +01:00
「✨」 feat: Prompt finished
This commit is contained in:
1 parent
272061eafc
commit
bbadc3e663
71 files changed
+83
-86
No files matched your search
+4
-1
@@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
char set_env(char **env, const char *name, char *content);
|
||||
char *get_hostname(void);
|
||||
char *get_prompt(void);
|
||||
char *get_pwd(void);
|
||||
|
||||
#endif
|
||||
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
+5
-47
@@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/*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)
|
||||
{
|
||||
char *test;
|
||||
char **lll;
|
||||
char *ret = NULL;
|
||||
char *prompt;
|
||||
|
||||
(void)ac;
|
||||
(void)av;
|
||||
(void)env;
|
||||
while (1)
|
||||
{
|
||||
ret = get_prompt();
|
||||
test = readline(ret);
|
||||
free(ret);
|
||||
prompt = get_prompt();
|
||||
test = readline(prompt);
|
||||
add_history(test);
|
||||
lll = ft_split(test, ' ');
|
||||
if (!*lll)
|
||||
@@ -92,6 +50,6 @@ int main(int ac, char **av, char **env)
|
||||
if (is_str(test, "exit"))
|
||||
break;
|
||||
}
|
||||
//ft_freearr((void **)lll);
|
||||
//ft_free("a", &lll);
|
||||
return (0);
|
||||
}
|
||||
@@ -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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
char *hostname;
|
||||
char *tmp;
|
||||
int host_file;
|
||||
|
||||
//host_file = open();
|
||||
tmp = hostname;
|
||||
while (*tmp)
|
||||
tmp++;
|
||||
return
|
||||
}*/
|
||||
#include "libft.h"
|
||||
#include "minishell.h"
|
||||
|
||||
char *get_prompt(void)
|
||||
{
|
||||
char **prompt;
|
||||
char *ret = NULL;
|
||||
char *home;
|
||||
char **tmp;
|
||||
char *prompt;
|
||||
|
||||
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++;
|
||||
prompt = getenv("USER");
|
||||
prompt = ft_strjoin(prompt, "@");
|
||||
prompt = ft_strjoin_free(prompt, get_hostname());
|
||||
prompt = ft_strjoin_free_s1(prompt, ":");
|
||||
prompt = ft_strjoin_free(prompt, get_pwd());
|
||||
prompt = ft_strjoin_free_s1(prompt, "$ ");
|
||||
return (prompt);
|
||||
}
|
||||
free(prompt);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -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