-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.c
More file actions
52 lines (46 loc) · 841 Bytes
/
format.c
File metadata and controls
52 lines (46 loc) · 841 Bytes
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"header.h"
void getcwdstr(char *arr)
{
getcwd(arr,sizeof(char)*10000);
}
void gethome(char *from,char *to)
{
from[strlen(from)-5]='\0';
realpath(from,to);
}
char *getusername()
{
return getenv("USER");
}
void gethname(char *arr)
{
gethostname(arr,10000);
}
void printterm(char *usr,char *host,char *path)
{
printf("\033[1;31m<\033[0m\033[1;32m%s\033[0m\033[1;33m@\033[0m\033[1;32m%s\033[0m:\033[1;34m%s\033[0m\033[1;31m>\033[0m ",usr,host,path);
}
int makerel(char *path,char *home,char *path2)
{
if(strlen(path)<strlen(home))
{
strcpy(path2,path);
return 0;
}
for(int i=0;i<strlen(home);i++)
{
if(path[i]!=home[i])
{
strcpy(path2,path);
return 0;
}
}
int i;
for(i=strlen(home);i<strlen(path);i++)
{
path2[i-strlen(home)+1]=path[i];
}
path2[0]='~';
path2[i-strlen(home)+1]='\0';
return 1;
}