From 6fe039c3e7d3a08be21a2e718b07ee8e07b4cc7d Mon Sep 17 00:00:00 2001 From: guamss Date: Sat, 1 Jul 2023 11:51:36 +0200 Subject: [PATCH] update get_prompt() --- src/input/input.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/input/input.c b/src/input/input.c index 77626c2..6d07ffb 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -4,13 +4,13 @@ #include #include #include "../../lib/bozolib/bozolib.h" +#include "../../lib/bozolib/src/str/str.h" #include "../env/env.h" #include static char* get_prompt(lst** env) { char* out; - int size; char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == NULL) return NULL; @@ -31,16 +31,12 @@ static char* get_prompt(lst** env) { strcpy(cwd, "~"); strcat(cwd, cwd + strlen(home)); - } - size = strlen(user) + strlen(hostname_buff) + strlen(cwd) + 9; - out = malloc(size*sizeof(char)); - if(out == NULL) - return NULL; - sprintf(out, "[%s@%s] > %s ",user, hostname_buff, cwd); + } + out = str_merger(8, "[", user, "@", hostname_buff, "]", " > ", cwd, " "); if (strcmp(user, "root") == 0) - strcat(out, "# "); + out = str_merger(2, out, "# "); else - strcat(out, "$ "); + out = str_merger(2, out, "$ "); return out; }