-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.c
More file actions
52 lines (43 loc) · 1.1 KB
/
display.c
File metadata and controls
52 lines (43 loc) · 1.1 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
#include "headers.h"
void display(char *add_root)
{
long long int i,j,k,len_root,len_curd;
char add_curd[10000],add_display[10000],host[10000],* user;
user = (char*)malloc(sizeof(char)*10000);
getcwd(add_curd,10000);
len_root = strlen(add_root);
len_curd = strlen(add_curd);
if(len_curd<len_root)
{
strcpy(add_display, add_curd);
}
else
{
// strcpy(add_display, "testing");
for(i=0;i<len_root;i++)
{
if(add_curd[i]!=add_root[i])
{
strcpy(add_display,add_curd);
break;
}
}
if(i >= len_root)
{
add_display[0]='~';
// add_display[1]='/';
j=1;
for(;i<len_curd;i++)
{
add_display[j++] = add_curd[i];
}
add_display[j]='\0';
}
}
// printf("%s",add_display);
user = getlogin();
gethostname(host,10000);
// printf("%s %s",user,host);
printf("\033[1;31m%s@%s\033[0m:",user,host);
printf("\033[1;34m%s\033[0m$ ",add_display);
}