-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.c
executable file
·56 lines (50 loc) · 953 Bytes
/
prompt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "minishell.h"
void print_start(void)
{
printf("%s", LINE_1);
printf("%s", LINE_2);
printf("%s", LINE_3);
printf("%s", LINE_4);
printf("%s", LINE_5);
}
char *return_path(void)
{
char *home;
char cwd[4098];
char *path;
home = getenv("HOME");
getcwd(cwd, 4097);
if (ft_memcmp(home, cwd, ft_strlen(home)))
path = ft_strdup(cwd);
else
path = ft_strjoin("~", cwd + ft_strlen(home));
return (path);
}
void ft_free(char **str)
{
if (*str)
{
free(*str);
*str = NULL;
}
}
void print_prompt(t_sh *cmd)
{
cmd->envp = return_path();
cmd->temp = cmd->envp;
cmd->envp = ft_strjoin(cmd->envp, "$ ");
ft_free(&cmd->temp);
cmd->temp = ft_strjoin("\033[0;32mMinishell@42rio:\033[0:39m", cmd->envp);
ft_free(&cmd->envp);
cmd->prompt = readline(cmd->temp);
if (cmd->prompt && cmd->prompt[0])
add_history(cmd->prompt);
ft_free(&cmd->temp);
}
void freetwo_voids(t_sh *s, t_env *s2)
{
if (s)
free(s);
if (s2)
free(s2);
}