maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
prompt.c File Reference
#include "tokens.h"
#include "env.h"
Include dependency graph for prompt.c:

Go to the source code of this file.

Functions

char * generate_prompt (t_ms_data *data)
 
char * generate_prompt_string (t_ms_data *data, char *pwd, char *home_dir)
 
void print_maxishell (void)
 

Function Documentation

◆ generate_prompt()

char * generate_prompt ( t_ms_data data)

Definition at line 20 of file prompt.c.

21{
22 char *prompt;
23 size_t prompt_len;
24
25 prompt_len = ft_strlen("🌴 @maxishell$ ") + \
26 ft_strlen(getenv("LOGNAME"));
27 prompt = (char *)malloc(prompt_len + 1);
28 if (!prompt)
29 exit(EXIT_FAILURE);
30 ft_strcpy(prompt, "🌴 ");
31 ft_strcat(prompt, getenv("LOGNAME"));
32 ft_strcat(prompt, "@maxishell$ ");
33 (void)data;
34 return (prompt);
35}
#define EXIT_FAILURE
Definition exit_status.h:17
char * ft_strcpy(char *dest, const char *src)
Definition ft_strcpy.c:25
size_t ft_strlen(const char *s)
Definition ft_strlen.c:15
char * ft_strcat(char *dest, char *src)
Definition ft_strcat.c:26

References EXIT_FAILURE, ft_strcat(), ft_strcpy(), and ft_strlen().

Here is the call graph for this function:

◆ generate_prompt_string()

char * generate_prompt_string ( t_ms_data data,
char *  pwd,
char *  home_dir 
)

Definition at line 37 of file prompt.c.

39{
40 char *temp_pwd;
41
42 pwd = get_env(data->envp, "PWD");
43 if (pwd)
44 {
45 home_dir = get_env(data->envp, "HOME");
46 if (home_dir && ft_strncmp(pwd, home_dir, ft_strlen(home_dir)) == 0)
47 {
48 temp_pwd = ft_strjoin("~", pwd + ft_strlen(home_dir));
49 free(pwd);
50 pwd = temp_pwd;
51 }
52 }
53 return (pwd);
54}
char * get_env(t_env *envp, const char *key)
Definition env.c:59
char * ft_strjoin(char const *s1, char const *s2)
Definition ft_strjoin.c:23
int ft_strncmp(const char *s1, const char *s2, size_t n)
Definition ft_strncmp.c:24
t_env * envp
Definition shell.h:24

References s_ms_data::envp, ft_strjoin(), ft_strlen(), ft_strncmp(), and get_env().

Here is the call graph for this function:

◆ print_maxishell()

void print_maxishell ( void  )

Definition at line 56 of file prompt.c.

57{
58 ft_printf("\033[1;33m\n\n\n\n\n");
59 ft_printf("β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–‘"
60 "β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘\n");
61 ft_printf("β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘β–‘"
62 "β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘\n");
63 ft_printf("β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–‘β•šβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"
64 "β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘\n");
65 ft_printf("β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•‘β–‘β•šβ•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•"
66 "β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘\n");
67 ft_printf("β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β–‘"
68 "β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—\n");
69 ft_printf("β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β–‘β–‘"
70 "β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β•\n");
71 ft_printf("\n");
72 ft_printf(" \033[1;34m"
73 "Version 1.0.0\033[0m\n");
74 ft_printf(" \033[1;36m"
75 "By Димас ΠΈ Ромас\033[0m\n");
76 ft_printf("\n");
77}
int ft_printf(const char *format,...)
Definition ft_printf.c:37

References ft_printf().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: