-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_utils.c
More file actions
43 lines (36 loc) · 815 Bytes
/
shell_utils.c
File metadata and controls
43 lines (36 loc) · 815 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
void clearScreen(){
printf("\033[H\033[J");
}
char * trim(char *s){
char *p = s;
int len = strlen(p);
while(isspace(p[len-1]))
p[--len] = '\0';
while(*p && isspace(*p))
p++, len--;
return p;
}
void getPrompt(char *prompt){
char curr_dir[CWD_LEN];
getcwd(curr_dir, CWD_LEN);
char * user = getenv("USER");
char result[CWD_LEN] = "";
strcat(result, "[");
strcat(result, user);
strcat(result, "]");
strcat(result, "[");
strcat(result, curr_dir);
strcat(result, "]\n$$ ");
strcpy(prompt, result);
}
int getInput(char * ip){
char prompt[CWD_LEN];
getPrompt(prompt);
char * buff = readline(prompt);
if(strlen(buff) != 0){
add_history(buff);
strcpy(ip, buff);
return 1;
}
return 0;
}