~emersion/mrsh

0ffd30ec3f1f479f333242495f8aa3b29f2f5f93 — Drew DeVault 3 years ago 1ceb1d9
Source ~/.profile on startup
1 files changed, 18 insertions(+), 0 deletions(-)

M main.c
M main.c => main.c +18 -0
@@ 1,6 1,8 @@
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <limits.h>
#include <mrsh/ast.h>
#include <mrsh/builtin.h>
#include <mrsh/parser.h>
#include <mrsh/shell.h>
#include <stdlib.h>


@@ 36,6 38,20 @@ static void print_ps1(struct mrsh_state *state) {
	fflush(stderr);
}

static void source_profile(struct mrsh_state *state) {
	char path[PATH_MAX + 1];
	int n = snprintf(path, sizeof(path), "%s/.profile", getenv("HOME"));
	if (n == sizeof(path)) {
		fprintf(stderr, "Warning: $HOME/.profile is longer than PATH_MAX\n");
		return;
	}
	if (access(path, F_OK) == -1) {
		return;
	}
	char *profile_argv[2] = { ".", path };
	mrsh_run_builtin(state, 2, profile_argv);
}

static const char *get_alias(const char *name, void *data) {
	struct mrsh_state *state = data;
	return mrsh_hashtable_get(&state->aliases, name);


@@ 72,6 88,8 @@ int main(int argc, char *argv[]) {
	char *prev_ppid = mrsh_hashtable_set(&state.variables, "PPID", ppid_str);
	free(prev_ppid);

	source_profile(&state);

	// TODO: set PWD

	struct mrsh_parser *parser = mrsh_parser_create(state.input);