modif sur le makefile, ~ dans le prompt
This commit is contained in:
9
Makefile
9
Makefile
@ -6,7 +6,7 @@
|
||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||
# Updated: 2024/02/17 04:34:37 by tomoron ### ########.fr #
|
||||
# Updated: 2024/02/18 15:45:58 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -53,7 +53,9 @@ $(OBJS_DIR)%.o : $(SRCS_DIR)%.c | $(OBJS_DIR)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS_DIR)
|
||||
make --no-print-directory -C ./libft clean
|
||||
make --no-print-directory -C ./libft fclean
|
||||
|
||||
bonus: all
|
||||
|
||||
install: $(NAME)
|
||||
cp $(NAME) ~/.local/bin/msh
|
||||
@ -61,8 +63,7 @@ install: $(NAME)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
make --no-print-directory -C ./libft fclean
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
.PHONY: all clean fclean re install bonus
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* debug.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/15 14:16:47 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/16 16:34:53 by tomoron ### ########.fr */
|
||||
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 15:46:51 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,7 +18,7 @@ void print_parsed_cmd(t_cmd *cmd)
|
||||
{
|
||||
printf("[");
|
||||
if (cmd->type == ARG)
|
||||
printf("ARG : %s", cmd->token);
|
||||
printf("ARG : \"%s\"", cmd->token);
|
||||
else if (cmd->type == PIPE)
|
||||
printf("PIPE");
|
||||
else if (cmd->type == RED_O)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/17 02:54:36 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/17 04:26:57 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/18 13:35:11 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,7 +19,9 @@ t_cmd *handle_alias(t_cmd *cmd, t_env *env, t_alias *alias)
|
||||
char *alias_command;
|
||||
|
||||
alias_command = 0;
|
||||
if(cmd && cmd->type == ARG)
|
||||
if (!cmd)
|
||||
return(0);
|
||||
if(cmd->type == ARG)
|
||||
alias_command = ft_get_alias(alias,cmd->token);
|
||||
if(!alias_command)
|
||||
return(cmd);
|
||||
@ -27,6 +29,7 @@ t_cmd *handle_alias(t_cmd *cmd, t_env *env, t_alias *alias)
|
||||
tmp = res;
|
||||
while(tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = cmd;
|
||||
tmp->next = cmd->next;
|
||||
free(cmd);
|
||||
return(res);
|
||||
}
|
||||
|
15
srcs/main.c
15
srcs/main.c
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/17 04:30:26 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/18 13:50:32 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,6 +18,7 @@ char *get_prompt(void)
|
||||
{
|
||||
char *res;
|
||||
char cwd_buffer[100];
|
||||
char *cwd;
|
||||
|
||||
res = ft_strjoin_free("\001", ft_get_color(10, 255, 80), 2);
|
||||
res = ft_strjoin_free(res, "\002", 1);
|
||||
@ -26,7 +27,13 @@ char *get_prompt(void)
|
||||
res = ft_strjoin_free(res, "minishell\001\033[0m\002:\001", 1);
|
||||
res = ft_strjoin_free(res, ft_get_color(80, 80, 255), 3);
|
||||
res = ft_strjoin_free(res, "\002", 1);
|
||||
res = ft_strjoin_free(res, getcwd(cwd_buffer, 99), 1);
|
||||
cwd = getcwd(cwd_buffer, 99);
|
||||
if(!ft_strncmp(cwd_buffer, getenv("HOME"), ft_strlen(getenv("HOME"))))
|
||||
{
|
||||
cwd += ft_strlen(getenv("HOME")) - 1;
|
||||
cwd[0] = '~';
|
||||
}
|
||||
res = ft_strjoin_free(res, cwd, 1);
|
||||
res = ft_strjoin_free(res, "\001\033[0m\002$ ", 1);
|
||||
return (res);
|
||||
}
|
||||
@ -73,6 +80,7 @@ int main(int argc, char **argv, char **envp)
|
||||
(void)argv;
|
||||
env = get_env(envp);
|
||||
aliases = 0;
|
||||
aliases = alias_add_back(0, ft_strdup("test"), ft_strdup("echo test")); // debug
|
||||
if (env)
|
||||
handle_minishellrc(env, aliases);
|
||||
while (env && command)
|
||||
@ -84,9 +92,10 @@ int main(int argc, char **argv, char **envp)
|
||||
free(prompt);
|
||||
add_history(command);
|
||||
parsed_cmd = parse_command(command, env);
|
||||
print_parsed_cmd(parsed_cmd);//debug
|
||||
parsed_cmd = handle_alias(parsed_cmd, env, aliases);
|
||||
free(command);
|
||||
//print_parsed_cmd(parsed_cmd);//debug
|
||||
print_parsed_cmd(parsed_cmd);//debug
|
||||
exec_command(parsed_cmd, env, aliases);
|
||||
free_cmd(parsed_cmd);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/17 04:30:53 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/18 13:19:19 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -78,5 +78,6 @@ int cd(t_cmd *args);
|
||||
int alias(t_cmd *args, t_alias *aliases);
|
||||
void free_alias(t_alias *alias);
|
||||
char *ft_get_alias(t_alias *alias, char *var_name);
|
||||
t_alias *alias_add_back(t_alias *alias, char *name, char *value);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/17 04:25:54 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/18 12:41:34 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "minishell.h"
|
||||
@ -51,7 +51,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
||||
(*cmd)++;
|
||||
i += add_var_to_str(res + i, cmd, env);
|
||||
}
|
||||
if(**cmd == '~' && !*in_quote && !*in_dquote)
|
||||
else if(**cmd == '~' && !*in_quote && !*in_dquote)
|
||||
i+= add_home_to_str(res + i);
|
||||
else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote))
|
||||
|| (**cmd != '\'' && **cmd != '"'))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/17 00:23:02 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/18 12:41:23 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -58,7 +58,7 @@ int get_token_len(char *command, t_env *env)
|
||||
in_quote = !in_quote;
|
||||
if (*command == '$' && !in_quote)
|
||||
res += get_var_len(&command, env);
|
||||
if (*command == '~' && !in_quote && !in_dquote)
|
||||
else if (*command == '~' && !in_quote && !in_dquote)
|
||||
res += ft_strlen(getenv("HOME"));
|
||||
else if (*command != '\'' && *command != '"')
|
||||
res++;
|
||||
|
Reference in New Issue
Block a user