🔨」 fix: Fixed prompt with env function

This commit is contained in:
2024-05-27 19:02:07 +02:00
parent ebe3560d03
commit c6d1149642
4 changed files with 15 additions and 14 deletions

View File

@ -31,9 +31,6 @@
# include "execution.h" # include "execution.h"
char set_env(char **env, const char *name, char *content); char set_env(char **env, const char *name, char *content);
char *get_hostname(void);
char *get_prompt(void);
char *get_pwd(void);
bool is_str(char *src, char *dst); bool is_str(char *src, char *dst);
#endif #endif

View File

@ -6,13 +6,15 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 13:48:05 by adjoly #+# #+# */ /* Created: 2024/05/19 13:48:05 by adjoly #+# #+# */
/* Updated: 2024/05/19 14:20:45 by adjoly ### ########.fr */ /* Updated: 2024/05/27 18:59:56 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef PROMPT_H #ifndef PROMPT_H
# define PROMPT_H # define PROMPT_H
# include "env.h"
/** /**
* @brief return the short hostname from /etc/hostname * @brief return the short hostname from /etc/hostname
* or return nixos if file doesn't exist or is empty * or return nixos if file doesn't exist or is empty
@ -27,13 +29,13 @@ char *get_hostname(void);
* *
* @return (char *) the pwd * @return (char *) the pwd
*/ */
char *get_pwd(void); char *get_pwd(t_env env);
/** /**
* @brief return the full prompt * @brief return the full prompt
* *
* @prompt (char *) the prompt * @prompt (char *) the prompt
*/ */
char *get_prompt(void); char *get_prompt(t_env env);
#endif #endif

View File

@ -6,18 +6,19 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */ /* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */
/* Updated: 2024/05/21 21:02:18 by adjoly ### ########.fr */ /* Updated: 2024/05/27 19:01:17 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include "prompt.h" #include "prompt.h"
#include "env.h"
char *get_prompt(void) char *get_prompt(t_env env)
{ {
char *prompt; char *prompt;
prompt = getenv("USER"); prompt = env_get_value("USER", &env);//getenv("USER");
if (!prompt) if (!prompt)
prompt = ft_strdup("nixos"); prompt = ft_strdup("nixos");
prompt = ft_strjoin(prompt, "@"); prompt = ft_strjoin(prompt, "@");
@ -29,7 +30,7 @@ char *get_prompt(void)
prompt = ft_strjoin_free_s1(prompt, ":"); prompt = ft_strjoin_free_s1(prompt, ":");
if (!prompt) if (!prompt)
return (NULL); return (NULL);
prompt = ft_strjoin_free(prompt, get_pwd()); prompt = ft_strjoin_free(prompt, get_pwd(env));
if (!prompt) if (!prompt)
return (NULL); return (NULL);
prompt = ft_strjoin_free_s1(prompt, "$ "); prompt = ft_strjoin_free_s1(prompt, "$ ");

View File

@ -6,22 +6,23 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */ /* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */
/* Updated: 2024/05/27 12:52:07 by adjoly ### ########.fr */ /* Updated: 2024/05/27 19:00:47 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <stdlib.h> #include <stdlib.h>
#include "libft.h" #include "libft.h"
#include "env.h"
char *get_pwd(void) char *get_pwd(t_env env)
{ {
char *pwd; char *pwd;
char *home; char *home;
pwd = getenv("PWD"); pwd = env_get_value("PWD", &env);//getenv("PWD");
if (!pwd) if (!pwd)
return (NULL); return (NULL);
home = getenv("HOME"); home = env_get_value("HOME", &env);//getenv("HOME");
if (!pwd) if (!pwd)
return (NULL); return (NULL);
if (!ft_strncmp(pwd, home, ft_strlen(home))) if (!ft_strncmp(pwd, home, ft_strlen(home)))