This commit is contained in:
Loic Deridder
2025-01-15 13:41:40 +01:00
parent eedfe4a0ee
commit 0ec78ee34c
11 changed files with 182 additions and 48 deletions

View File

@@ -5,7 +5,7 @@ char *powerline(void)
char *pwd;
char *tilt;
pwd = getenv("PWD");
pwd = getcwd(NULL, 0);
if (ft_strncmp(pwd, "/home/", 6) == 0)
{
pwd = pwd + 6;
@@ -22,20 +22,41 @@ char *powerline(void)
return (readline(""));
}
char **ft_setnewenv(void)
{
char **envp;
envp = malloc(sizeof(char *) * 2);
if (!envp)
return (NULL);
envp[0] = ft_strjoin("PWD=", getcwd(NULL, 0));
envp[1] = ft_strdup("SHLVL=1");
if (!envp[0] || !envp[1])
return (ft_free(&envp[0]), ft_free(&envp[1]), NULL);
return (envp);
}
int main(int ac, char **av, char **envp)
{
char *input;
(void)ac;
(void)av;
(void)envp;
if (!envp[0])
envp = ft_setnewenv();
while (1)
{
input = powerline();
if (ft_strncmp(input, "exit", 4) == 0)
builtin_exit(&input[5], true);
builtin_exit(input, true);
if (ft_strncmp(input, "pwd", 3) == 0)
builtin_pwd(input);
if (ft_strncmp(input, "echo", 4) == 0)
builtin_echo(input, envp);
if (ft_strncmp(input, "env", 3) == 0)
builtin_env(input, envp);
if (ft_strncmp(input, "unset", 5) == 0)
builtin_unset(input, envp);
free(input);
}
return (0);