-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.c
More file actions
36 lines (31 loc) · 1.05 KB
/
Copy pathprompt.c
File metadata and controls
36 lines (31 loc) · 1.05 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
#include "headers.h"
#include "common.h"
void prompt(int pflag, char *pcom)
{
// printf("%s\n", uname);
// printf("%s\n", sysname);
// printf("%s\n", rootdir);
// getting the absolute path of the current directory
char currdir[4096];
if (getcwd(currdir, 4096) == NULL)
{
printf(ERROR_COLOR "Error getting path.\n" DEFAULT_COLOR);
return;
}
char prom[4096];
if (strcmp(rootdir, currdir) == 0)
strcpy(prom, "~");
else if (strstr(rootdir, currdir))
strcpy(prom, currdir); // outside shell: absolute path
else
{
strcpy(prom, "~");
strcat(prom, currdir + strlen(rootdir)); // inside shell: relative path
}
char *command = strtok(pcom, " \n\t");
// printf(CYAN_PROMPT "<%s@%s:" PURPLE_PROMPT "%s" CYAN_PROMPT ">" DEFAULT_PROMPT " ", uname, sysname, prom);
printf(CYAN_PROMPT "<%s@%s:" PURPLE_PROMPT "%s", uname, sysname, prom);
if (pflag != 0)
printf(YELLOW_PROMPT " %s: %ds", command, pflag);
printf(CYAN_PROMPT ">" DEFAULT_PROMPT " ");
}