cd fonctionne dans les deux sens

This commit is contained in:
PrStein 2022-04-08 02:26:25 +02:00
parent 1e8fe6e5a7
commit 2841d5b920

View File

@ -124,6 +124,16 @@ void reboot_pwd(t_s_cmd *cmd, int i)
free(str); free(str);
} }
int find_it(char **str, char *s)
{
int i;
i = 0;
while (str[i] && ft_strncmp(str[i], s, ft_strlen(s)))
i++;
return (i);
}
void open_directory(t_s_cmd *cmd) void open_directory(t_s_cmd *cmd)
{ {
char **str; char **str;
@ -134,10 +144,19 @@ void open_directory(t_s_cmd *cmd)
if (!cmd->args[1]) if (!cmd->args[1])
{ {
// reboot_pwd(cmd, j); // reboot_pwd(cmd, j);
if (tab_len(str) > 3)
{
while (j-- > 3) while (j-- > 3)
if (chdir("..") == 0) if (chdir("..") == 0)
del_one(cmd); del_one(cmd);
} }
else
{
char *p = ft_substr(cmd->env[find_it(cmd->env, "HOME=")], 6, ft_strlen(cmd->env[find_it(cmd->env, "HOME=")]));
chdir(p);
// printf("%s\n", p);
}
}
if (tab_len(cmd->args) == 2) if (tab_len(cmd->args) == 2)
{ {
if (cmd->args[1][0] == '~') if (cmd->args[1][0] == '~')