diff --git a/src/expander/expander_parse_string.c b/src/expander/expander_parse_string.c index 1b2d213..e5588df 100644 --- a/src/expander/expander_parse_string.c +++ b/src/expander/expander_parse_string.c @@ -42,7 +42,13 @@ char *expander_parse_string(char *s, t_minishell *msh) j = 0; while (s[i]) { - if (s[i] == '$' && s[i + 1] && current) + if (s[i] == '~' && current) + { + i++; + expander_expand_dollar(s + i, string, &j, current); + current = current->next; + } + else if (s[i] == '$' && s[i + 1] && current) { i++; i += expander_expand_dollar(s + i, string, &j, current); diff --git a/src/expander/expander_parse_variables.c b/src/expander/expander_parse_variables.c index 7bb70b6..310bfc0 100644 --- a/src/expander/expander_parse_variables.c +++ b/src/expander/expander_parse_variables.c @@ -10,6 +10,8 @@ /* */ /* ************************************************************************** */ +#include "environment.h" +#include "libft.h" #include "minishell.h" static char *ft_itoa_safe(t_minishell *msh, int n) @@ -54,6 +56,8 @@ t_list *expander_parse_variables(const char *s, t_minishell *msh) ft_lstadd_back(&var_list, ft_lstnew_safe(msh, NULL)); } } + else if (s[i] == '~') + ft_lstadd_back(&var_list, ft_lstnew_safe(msh, environment_get(msh, "HOME"))); i++; } return (var_list); diff --git a/src/parser/parser_process_token.c b/src/parser/parser_process_token.c index 4c5a6c8..f0898c4 100644 --- a/src/parser/parser_process_token.c +++ b/src/parser/parser_process_token.c @@ -27,7 +27,9 @@ static int parser_should_expand(t_list *value) while (token->value[i]) { t_val = token->value; - if (t_val[i] == '$' && expander_character_valid(t_val[i + 1])) + if (t_val[i] == '~' && (t_val[i + 1] == '/' || t_val[i + 1] == ' ' || t_val[i + 1] == 0) && token->type == T_WORD) + return (1); + else if (t_val[i] == '$' && expander_character_valid(t_val[i + 1])) return (1); else if (t_val[i] == '$' && t_val[i + 1] == '?') return (1);