mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix: Made a cd wayyy more simpler, thx bonsthie
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/22 15:07:24 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/29 16:36:56 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/03 11:45:04 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -36,6 +36,7 @@ char *__relative_path(char *args, char *pwd)
|
||||
{
|
||||
char **path;
|
||||
char **tmp;
|
||||
char *ret;
|
||||
char *new_path;
|
||||
|
||||
path = ft_split(args, '/');
|
||||
@ -47,7 +48,7 @@ char *__relative_path(char *args, char *pwd)
|
||||
{
|
||||
if (is_str(*tmp, ".."))
|
||||
new_path = __get_parent_directory(new_path);
|
||||
else if (*tmp)
|
||||
else if (*tmp && !is_str(*tmp, "."))
|
||||
{
|
||||
ft_strlcat(new_path, "/", ft_strlen(new_path) + 2);
|
||||
ft_strlcat(new_path, *tmp, ft_strlen(new_path) + \
|
||||
@ -55,9 +56,9 @@ char *__relative_path(char *args, char *pwd)
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
*tmp = ft_strdup(new_path);
|
||||
ft_free("a", path);
|
||||
return (*tmp);
|
||||
ret = ft_strdup(new_path);
|
||||
ft_free("a", &path);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void ft_cd(t_env *env, char *args)
|
||||
@ -67,22 +68,23 @@ void ft_cd(t_env *env, char *args)
|
||||
int ret;
|
||||
|
||||
new_pwd = NULL;
|
||||
pwd = ret_cwd();
|
||||
pwd = ft_strdup(ret_cwd());
|
||||
if (!args)
|
||||
new_pwd = env_get_value("HOME", env);
|
||||
else if (args[0] == '/')
|
||||
new_pwd = ft_strdup(args);
|
||||
//else if (args[0] == '/')
|
||||
//new_pwd = ft_strdup(args);
|
||||
else if (args[0] == '-')
|
||||
new_pwd = env_get_value("OLDPWD", env);
|
||||
else
|
||||
new_pwd = __relative_path(args, pwd);
|
||||
new_pwd = ft_strdup(args);
|
||||
//new_pwd = __relative_path(args, pwd);
|
||||
ret = chdir(new_pwd);
|
||||
if (ret == -1)
|
||||
{
|
||||
printf("./minishell: cd: %s: %s\n", args, ERROR_NO_FILE);
|
||||
return ;
|
||||
}
|
||||
env_edit("PWD", ft_strdup(new_pwd), env);
|
||||
env_edit("OLDPWD", ft_strdup(pwd), env);
|
||||
env_edit("PWD", ft_strdup(ret_cwd()), env);
|
||||
env_edit("OLDPWD", pwd, env);
|
||||
free(args);
|
||||
}
|
||||
|
Reference in New Issue
Block a user