-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyshelldon.c
More file actions
62 lines (49 loc) · 1.74 KB
/
yshelldon.c
File metadata and controls
62 lines (49 loc) · 1.74 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
58
59
60
61
62
#include "internal_commands.h"
int main(int argc, char *argv[]) {
extern char **environ; //inicializa o ambiente privado
char atual[1024];
getcwd(atual,sizeof(atual)); //PEGANDO A PASTA ATUAL COMO PATH
strcat(atual,"/bin"); //SETANDO O /BIN
//strcat(atual,":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin");
setenv("PATH", atual, 1); //seta nosso bin como path
char title[100];
char command[100];
char permissions[] = "0770";
char* current_path = (char *)malloc(1024 * sizeof(char));
char home[] = "/home/";
strcat(current_path, home); strcat(current_path, getlogin()); // seta o path padrão para /home/user
sprintf(title, "%s@bashinga⚡", getlogin());
printf("\033]0;%s\007", title);
clearScreen();
if (argc >= 2) {
char line[100];
char ch;
FILE *file = fopen(argv[1], "r");
if (file == NULL) {
printf("fatal error: cannot open file '%s'\n", argv[1]);
// free(current_path);
// return 1;
} else {
while (fgets(line, sizeof(line), file) != NULL) {
line[strcspn(line, "\n")] = '\0';
printf("\e[1;33m%s\e[0m", line);
printf("\n");
call_internal_command(line, current_path);
}
fclose(file);
}
}
while (true) {
printUserFormat(current_path);
if (fgets(command, sizeof(command), stdin) == NULL) {
break;
}
else if (strcmp(command, "\n") == 0) {
continue;
}
command[strcspn(command, "\n")] = '\0';
call_internal_command(command, current_path);
}
free(current_path);
return 0;
}