-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec1.c
More file actions
29 lines (22 loc) · 751 Bytes
/
spec1.c
File metadata and controls
29 lines (22 loc) · 751 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
#include "headers.h"
// change this so that the executables directory works as home
void get_username_systemname_and_directory(const char *home_dir) {
char username[256];
char systemname[256];
char currentdir[4096];
struct passwd *pw = getpwuid(getuid());
if (pw) {
strcpy(username, pw->pw_name);
}
struct utsname info;
if (uname(&info) == 0) {
strcpy(systemname, info.nodename);
}
getcwd(currentdir, sizeof(currentdir));
// Replace home directory path with ~
if (strstr(currentdir, home_dir) == currentdir) {
printf("<%s@%s:~%s> ", username, systemname, currentdir + strlen(home_dir));
} else {
printf("<%s@%s:%s> ", username, systemname, currentdir);
}
}