diff --git a/.gitmodules b/.gitmodules index 692478d..5dc1446 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "lib/bozolib"] - url = git@git.chauvet.pro:starnakin/bozolib.git + url = https://git.chauvet.pro/starnakin/bozolib path = lib/bozolib diff --git a/src/exec/exec.c b/src/exec/exec.c index ade872a..87eac5d 100644 --- a/src/exec/exec.c +++ b/src/exec/exec.c @@ -36,12 +36,12 @@ int change_directory(char** args) { if(len(args)!=2) { - printf("Mauvais arguments\n"); + dprintf(2, "Mauvais arguments\n"); return 1; } if(chdir(args[1])!=0) { - printf("Mauvais chemin : %s\n", args[1]); + dprintf(2, "Mauvais chemin : %s\n", args[1]); return 1; } char cwd[PATH_MAX]; @@ -67,20 +67,4 @@ int builtin_execute(cmd** input, char** env) return exitcode; } -int main() -{ - cmd** tests; - tests = malloc(2*sizeof(cmd*)); - cmd test; - test.executable = "cd"; - test.args = malloc(3*sizeof(char*)); - test.args[0] = "cd"; - test.args[1] = ".."; - test.args[2] = NULL; - test.fd_in = 0; - test.fd_out = 1; - tests[0] = &test; - tests[1] = NULL; - builtin_execute(tests, NULL); - return 0; -} + diff --git a/src/main.c b/src/main.c index 8ba9a9b..adfe38b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,23 +1,12 @@ +#include "prompt/prompt.h" #include "./env/env.h" #include int main(int ac, char **av, char **env) { lst** lst_env; - lst* current; - struct s_env* content; (void) av; (void) ac; lst_env = env_init((const char **) env); - if (lst_env == NULL) - return (1); - current = *lst_env; - while (current != NULL) - { - content = current->content; - if (content == NULL) - printf("nil\n"); - printf("%s=%s\n", content->key, content->value); - current = current->next; - } + printf(get_prompt(lst_env)); } diff --git a/src/prompt/prompt.c b/src/prompt/prompt.c new file mode 100644 index 0000000..8c74edf --- /dev/null +++ b/src/prompt/prompt.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include "../../lib/bozolib/bozolib.h" +#include "../env/env.h" + +char* get_prompt(lst** env) +{ + char* out; + int size; + char cwd[PATH_MAX]; + if (getcwd(cwd, sizeof(cwd)) == NULL) + { + dprintf(2, "chemin inconnu"); + return NULL; + } + char* computer = get_env_variable(env, "COMPUTER"); + char* user = get_env_variable(env, "USER"); + char* home = get_env_variable(env, "HOME"); + if (computer == NULL) + computer = ""; + if (user == NULL) + user = ""; + else if (strncmp(home, cwd, strlen(home)) == 0) + { + strcpy(cwd, "~"); + strcat(cwd, cwd + strlen(home)); + } + size = snprintf(NULL, 0, "%s@%s>%s $",user, computer, cwd); + out = malloc(size*sizeof(char)); + if(out == NULL) + { + return NULL; + } + sprintf(out, "%s@%s > %s $",user, computer, cwd); + + return out; +} diff --git a/src/prompt/prompt.h b/src/prompt/prompt.h new file mode 100644 index 0000000..559c65e --- /dev/null +++ b/src/prompt/prompt.h @@ -0,0 +1,4 @@ +#pragma once +#include "../../lib/bozolib/bozolib.h" +char* get_prompt(lst** env); +