-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.h
More file actions
57 lines (53 loc) · 1.25 KB
/
prompt.h
File metadata and controls
57 lines (53 loc) · 1.25 KB
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
#ifndef PROMPT_H
#define PROMPT_H
#include "global.h"
void currwd()
{
struct utsname xname;
uname(&xname);
char currdirname[1000];
char *result = getcwd(currdirname, sizeof(currdirname));
int cflag = 0;
if (strlen(currdirname) < strlen(shelldir))
cflag = 1;
else
{
for (int i = 0; i < strlen(shelldir); i++)
if (shelldir[i] != currdirname[i])
{
cflag = 1;
break;
}
}
if (cflag == 1)
printf("%s", currdirname);
else
{
printf("~");
for (int i = strlen(shelldir); i < strlen(currdirname); i++)
printf("%c", currdirname[i]);
}
}
void prompt()
{
struct utsname xname;
uname(&xname);
struct passwd *p = getpwuid(getuid());
size_t username_size, hostname_size;
char *username = p->pw_name;
char *hostname = xname.nodename;
printf("\033[0;32m"); // prints in green
printf("<%s@%s", username, hostname);
printf("\033[0;33m"); // prints in yellow
printf(":");
currwd();
if (end_Sec - start_sec >= 1)
{
printf("took %lds", end_Sec - start_sec);
}
start_sec = 0;
end_Sec = 0;
printf("> ");
printf("\033[0m"); // resets stdout color
}
#endif