display_logged_user
This commit is contained in:
parent
91476b920d
commit
f32e77072f
20
main.c
20
main.c
@ -14,11 +14,14 @@
|
||||
|
||||
void PrintCurrentDir() { // pwd
|
||||
char cwd[MAX_SIZE];
|
||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
printf("[%s] $ ", cwd);
|
||||
} else {
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL) {
|
||||
perror("getcwd() error");
|
||||
}
|
||||
char* user = getenv("USER");
|
||||
if (user == NULL) {
|
||||
perror("getenv() error");
|
||||
}
|
||||
printf("[%s@%s] $ ", user, cwd);
|
||||
}
|
||||
|
||||
int ChangeDirectory(char** args) { // cd
|
||||
@ -34,8 +37,15 @@ int ChangeDirectory(char** args) { // cd
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PrintHelp() { // help
|
||||
void PrintHelp() { // help
|
||||
printf("-------------------------------------------------");
|
||||
printf("C Microshell implementation by Maciej Życzyński\n");
|
||||
printf("\"exit\" - exit the program");
|
||||
printf("\"help\" - display this menu");
|
||||
printf("Other bash commands work accordingly in child processes");
|
||||
printf("Currently logged user / working directory:");
|
||||
PrintCurrentDir();
|
||||
printf("-------------------------------------------------");
|
||||
}
|
||||
|
||||
int HandleBuiltInCommands(char* command, char** args) { // Manual implementation of commands unsupported by execvp()
|
||||
@ -55,7 +65,7 @@ int HandleBuiltInCommands(char* command, char** args) { // Manual implementation
|
||||
|
||||
int HandleCommand(char* command, char** args) { // Execute commands supported by execvp()
|
||||
if (execvp(command, args) == -1) {
|
||||
perror("Error executing command");
|
||||
printf("Error executing command\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user