-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.c
60 lines (57 loc) · 1.41 KB
/
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
57
58
59
60
#include "prompt.h"
#include "headers.h"
#include "main.h"
void prompt(char *cwd)
{
char host[1025];
host[1024] = '\0';
int hostname = gethostname(host, 1024);
if (hostname == -1)
{
perror("hostname: ");
}
else
{
struct passwd *pw;
pw = getpwuid(getuid());
if (pw == NULL)
{
perror("passwd: ");
}
else
{
if (strcmp(cwd, home) != 0)
{
printf("< ");
printf("\033[1;34m");
printf("%s", pw->pw_name);
printf("\033[0m");
printf("@");
printf("\033[1;34m");
printf("%s", host);
printf("\033[0m");
printf(" : ");
printf("\033[01;33m");
printf("%s", cwd);
printf("\033[0m");
printf(">");
}
else
{
printf("< ");
printf("\033[1;34m");
printf("%s", pw->pw_name);
printf("\033[0m");
printf("@");
printf("\033[1;34m");
printf("%s", host);
printf("\033[0m");
printf(" : ");
printf("\033[01;33m");
printf("~");
printf("\033[0m");
printf(">");
}
}
}
}