-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.c
42 lines (39 loc) · 923 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
#include "headers.h"
#define clear() printf("\033[H\033[J")
void prompt(char *dir)
{
char *username = getenv("USER");
char cwd[1024];
char hostname[1023 + 1];
gethostname(hostname, 1023 + 1);
getcwd(cwd, 1024);
printf("\033[1;32m%s@\033[0m", username);
printf("\033[1;32m%s\033[0m", hostname);
if (strlen(cwd) >= strlen(homeworkingdir))
{
printf(":");
printf("\033[1;34m~\033[0m");
int x = strlen(homeworkingdir);
for (int i = x; i < strlen(cwd); i++)
{
printf("\033[1;34m%c\033[0m", cwd[i]);
}
if (tim > 2)
{
printf("%s ", com);
printf(": %ds", tim);
}
tim = 0;
}
else
{
printf(":\033[1;34m%s\033[0m", cwd);
if (tim > 2)
{
printf(" %s : %ds ", com, tim);
}
tim = 0;
}
printf(">");
return;
}