Shell: source $HOME/.shellrc if found on Shell startup

This commit is contained in:
Bananymous 2023-10-03 10:24:36 +03:00
parent bb0989fdef
commit 44cb0af64f
2 changed files with 21 additions and 2 deletions

Binary file not shown.

View File

@ -691,6 +691,24 @@ int source_script(const BAN::String& path)
return ret;
}
bool exists(const BAN::String& path)
{
struct stat st;
return stat(path.data(), &st) == 0;
}
int source_shellrc()
{
if (char* home = getenv("HOME"))
{
BAN::String path(home);
MUST(path.append("/.shellrc"sv));
if (exists(path))
return source_script(path);
}
return 0;
}
int character_length(BAN::StringView prompt)
{
int length { 0 };
@ -717,7 +735,7 @@ BAN::String get_prompt()
{
const char* raw_prompt = getenv("PS1");
if (raw_prompt == nullptr)
return ""sv;
return "$ "sv;
BAN::String prompt;
for (int i = 0; raw_prompt[i]; i++)
@ -853,7 +871,8 @@ int main(int argc, char** argv)
if (argc >= 1)
setenv("SHELL", argv[0], true);
setenv("PS1", "\e[32m\\u@\\h\e[m:\e[34m\\~\e[m$ ", false);
source_shellrc();
tcgetattr(0, &old_termios);