summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/b_cd.c2
-rw-r--r--src/d_define.h8
-rw-r--r--src/m_argv.c2
-rw-r--r--src/m_minishell.c1
-rw-r--r--src/m_mshrc.c20
-rw-r--r--src/m_mshrc.h4
6 files changed, 32 insertions, 5 deletions
diff --git a/src/b_cd.c b/src/b_cd.c
index d2b1042..d82ab9c 100644
--- a/src/b_cd.c
+++ b/src/b_cd.c
@@ -136,7 +136,7 @@ uint8_t
{
if ((path = u_get_var_value("$HOME", msh)) == NULL)
{
- ft_dprintf(STDERR_FILENO, "minishell: cd: HOME not set\n");
+ ft_dprintf(STDERR_FILENO, "minishell: cd: %s\n", FT_FAIL_HOME_NOT_SET);
return (2);
}
}
diff --git a/src/d_define.h b/src/d_define.h
index 899a2e7..d38cb10 100644
--- a/src/d_define.h
+++ b/src/d_define.h
@@ -45,5 +45,13 @@
#define FT_FAIL_COMMAND_NOT_FOUND "command not found"
#define FT_FAIL_NO_OPTIONS "no options required"
#define FT_FAIL_TOO_MANY_ARGS "too many arguments"
+#define FT_FAIL_HOME_NOT_SET "HOME not set"
+
+/*
+** ====== FILES ======
+*/
+
+#define FT_MINISHELLRC ".minishellrc"
+#define FT_MINISHELL_HISTORY ".minishell_history"
#endif
diff --git a/src/m_argv.c b/src/m_argv.c
index 0c32e3b..25b386e 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -19,6 +19,7 @@
#include "d_define.h"
#include "m_comm.h"
#include "m_loop.h"
+#include "m_mshrc.h"
#include "s_struct.h"
uint8_t
@@ -30,6 +31,7 @@ uint8_t
if (argc == 1)
{
+ msh->ret = m_source_mshrc(msh);
msh->ret = m_loop(STDIN_FILENO, msh);
}
else if (argc > 1 && ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3) == 0)
diff --git a/src/m_minishell.c b/src/m_minishell.c
index 7a381ee..a538041 100644
--- a/src/m_minishell.c
+++ b/src/m_minishell.c
@@ -35,7 +35,6 @@ int
ft_dprintf(2, "%s\n", strerror(errno));
return (FT_RET_ALLOC);
}
- m_source_mshrc(msh);
ret = m_argv(argc, argv, msh);
s_destroy(msh);
return (ret);
diff --git a/src/m_mshrc.c b/src/m_mshrc.c
index acd64ec..f730113 100644
--- a/src/m_mshrc.c
+++ b/src/m_mshrc.c
@@ -11,15 +11,31 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
+#include "d_define.h"
#include "s_struct.h"
+#include "m_loop.h"
#include "u_vars.h"
-void
+uint8_t
m_source_mshrc(t_msh *msh)
{
- (void)msh;
+ int32_t fd;
+ char *home;
+ char file[2048];
+ uint8_t ret;
+
+ if ((home = u_get_var_value("$HOME", msh)) == NULL)
+ return (0);
+ ft_sprintf(file, "%s/%s", home, FT_MINISHELLRC);
+ ft_memdel((void*)&home);
+ if ((fd = open(file, O_RDONLY)) < 0)
+ return (0);
+ ret = m_loop(fd, msh);
+ close(fd);
+ return (ret);
}
diff --git a/src/m_mshrc.h b/src/m_mshrc.h
index 325b742..75daf15 100644
--- a/src/m_mshrc.h
+++ b/src/m_mshrc.h
@@ -13,8 +13,10 @@
#ifndef M_MSHRC_H
#define M_MSHRC_H
+#include <stdint.h>
+
#include "s_struct.h"
-void m_source_mshrc(t_msh *msh);
+uint8_t m_source_mshrc(t_msh *msh);
#endif