Files
42_INT_07_minishell/srcs/init/init_prompt.c
LuckyLaszlo afbb1cd2e0 shell_script()
+ reset "rl_event_hook" to NULL after here_doc()
+ split init.c in multiple files
+ submodule minishell_tests
2021-12-18 05:42:08 +01:00

55 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_prompt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
/* Updated: 2021/12/18 04:28:46 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *init_prompt_base(void)
{
char *prompt_base;
char *tmp;
tmp = getenv("USER");
if (!tmp)
tmp = getenv("LOGNAME");
if (!tmp)
tmp = U_DEFAULT_USER;
prompt_base = ft_strjoin(TERM_LIGHT_GREEN, tmp);
if (!prompt_base)
return (NULL);
prompt_base = ft_strjoinfree_s1(prompt_base, "@");
if (!prompt_base)
return (NULL);
tmp = getenv("NAME");
if (!tmp)
tmp = U_DEFAULT_NAME;
prompt_base = ft_strjoinfree_s1(prompt_base, tmp);
if (!prompt_base)
return (NULL);
prompt_base = ft_strjoinfree_s1(prompt_base, TERM_RESET":"TERM_LIGHT_BLUE);
if (!prompt_base)
return (NULL);
return (prompt_base);
}
char *init_prompt(char *prompt_base)
{
char *prompt;
prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0));
if (!prompt)
return (NULL);
prompt = ft_strjoinfree_s1(prompt, TERM_RESET U_PROMPT_END);
if (!prompt)
return (NULL);
return (prompt);
}