summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/b_cd.c15
-rw-r--r--src/e_builtins.c2
-rw-r--r--src/p_lcom_next.c22
-rw-r--r--src/p_lcom_next.h1
-rw-r--r--src/s_com.c2
5 files changed, 32 insertions, 10 deletions
diff --git a/src/b_cd.c b/src/b_cd.c
index 2248a89..d2b1042 100644
--- a/src/b_cd.c
+++ b/src/b_cd.c
@@ -32,14 +32,6 @@ static void
{
f_alloc_and_destroy_msh(msh);
}
- if (ft_strncmp("~/", *path, 2) == 0 || !ft_strncmp("~", *path, 2))
- {
- if (!(*path = ft_strsubst(*path,
- "~", u_get_var_value("$HOME", msh))))
- {
- f_alloc_and_destroy_msh(msh);
- }
- }
}
static void
@@ -142,8 +134,11 @@ uint8_t
}
else if (argc == 0)
{
- if (!(path = u_get_var_value("$HOME", msh)))
- return (1);
+ if ((path = u_get_var_value("$HOME", msh)) == NULL)
+ {
+ ft_dprintf(STDERR_FILENO, "minishell: cd: HOME not set\n");
+ return (2);
+ }
}
else
set_path(&path, args, msh);
diff --git a/src/e_builtins.c b/src/e_builtins.c
index c00114d..e1dbfbb 100644
--- a/src/e_builtins.c
+++ b/src/e_builtins.c
@@ -71,6 +71,8 @@ static void
msh->bu_ptr[bu_id](ptr->argv + 1, msh);
else if (bu_id == FT_ID_EXPORT)
b_export_mute(ptr->argv + 1, msh);
+ else if (bu_id == FT_ID_UNSET)
+ msh->bu_ptr[bu_id](ptr->argv + 1, msh);
else if (bu_id == FT_ID_EXIT && ret == 0)
{
s_line_clear(&msh->curr);
diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c
index 3f18ec1..b04d393 100644
--- a/src/p_lcom_next.c
+++ b/src/p_lcom_next.c
@@ -101,6 +101,28 @@ char
return (words);
}
+char
+ **p_subst_home(char *words[],
+ t_msh *msh)
+{
+ char *path;
+ char **ptr;
+
+ if ((path = u_get_var_value("$HOME", msh)) == NULL)
+ return (words);
+ ptr = words;
+ while (*ptr != NULL)
+ {
+ if (*ptr[0] == '~')
+ {
+ *ptr = ft_strsubst(*ptr, "~", path);
+ }
+ ptr++;
+ }
+ ft_memdel((void*)&path);
+ return (words);
+}
+
static void
p_register_word(char word[],
t_msh *msh)
diff --git a/src/p_lcom_next.h b/src/p_lcom_next.h
index f9ae416..dea86bd 100644
--- a/src/p_lcom_next.h
+++ b/src/p_lcom_next.h
@@ -19,6 +19,7 @@
char **p_subst_vars(char *words[], t_msh *msh);
char **p_subst_args(const char word[], int8_t redir);
+char **p_subst_home(char *word[], t_msh *msh);
char **p_check_args_equals(char *words[], t_msh *msh);
#endif
diff --git a/src/s_com.c b/src/s_com.c
index 1bde96c..550616c 100644
--- a/src/s_com.c
+++ b/src/s_com.c
@@ -117,6 +117,8 @@ t_com
return (NULL);
if ((words = p_subst_vars(words, msh)) == NULL)
return (NULL);
+ if ((words = p_subst_home(words, msh)) == NULL)
+ return (NULL);
words = p_check_args_equals(words, msh);
if (msh->env_fork_tmp[0][0] != '\0')
com_cpy_env_fork(&com, msh);