diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index cad7a03..00ff9e3 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -72,7 +72,7 @@ void fishLoop(Settings * settings){ pipe_redirection *r = getRedirection(); do { - printf("%s", settings->PS1); + printPS(settings->PS1, settings); line = fishReadLine(); r->to_use = 0; diff --git a/fish_shell/fish_settings.c b/fish_shell/fish_settings.c index a39c3bd..1f47255 100644 --- a/fish_shell/fish_settings.c +++ b/fish_shell/fish_settings.c @@ -46,6 +46,45 @@ void freeSettings(Settings *settings){ } } +void printPS(char* PS, Settings* s){ + int buf= FISH_BUFFER_SIZE; + int i = 0; + int slashed = 0; + char* path = NULL; + while (PS[i] != '\0'){ + if(slashed){ + switch (PS[i]) + { + case 'u': + printf("%s",s->passwd->pw_name); + break; + case 'p': + path = (char*) malloc(sizeof(char)*buf); + while(getcwd(path,buf) == NULL){ + buf+=FISH_BUFFER_SIZE; + free(path); + path = (char*) malloc(sizeof(char)*buf); + } + printf("%s",path); + free(path); + path = NULL; + break; + default:printf("%c",PS[i]); + + } + slashed = 0; + } + else if(PS[i] == '\\'){ + slashed = 1; + }else{ + printf("%c",PS[i]); + } + ++i; + } + +} + + char* extractVariable(char* filename, char* var){ FILE *file = fopen ( filename, "r" ); int var_size = strlen(var); @@ -81,3 +120,5 @@ char* extractVariable(char* filename, char* var){ } + + diff --git a/fish_shell/fish_settings.h b/fish_shell/fish_settings.h index eac5988..e941427 100644 --- a/fish_shell/fish_settings.h +++ b/fish_shell/fish_settings.h @@ -9,6 +9,7 @@ Settings * getSettings(); //TESTEDssssss void freeSettings(Settings *settings); //TESTED char* extractVariable(char* filename, char* var);//TESTED +void printPS(char* PS, Settings* s); #endif //FISH_FISH_SETTINGS_H