Browse Source

Evaluate $XDG_CONFIG_HOME/esh/eshrc file on start

master
Jake Wakeling 4 months ago
parent
commit
65268ba9de
  1. 1
      CHANGELOG
  2. 26
      src/main.c

1
CHANGELOG

@ -4,6 +4,7 @@
* Implement command history
* Implement configuration
* Switch to AST parsing
* Evaluate $XDG_CONFIG_HOME/esh/eshrc file on start
0.4.0, 2021-04-01
* Fix SIGINT handling at prompt

26
src/main.c

@ -37,6 +37,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
#include "cll/error.h"
#include "cll/optget.h"
#include <sys/stat.h>
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
@ -59,6 +61,7 @@ static jmp_buf jmp;
static sig_atomic_t jmpflag = false;
static void reset(int signo);
static void eshrc(void);
static void hlp(void);
static void ver(void);
@ -76,6 +79,8 @@ int main(int ac, char *av[]) { (void)(ac); A0 = av[0];
signal(SIGINT, &reset); signal(SIGTSTP, SIG_IGN); signal(SIGQUIT, SIG_IGN);
if (errno) { warn("%s", serr()); }
eshrc();
do {
if (sigsetjmp(jmp, 1)) { fputc('\n', stdout); } jmpflag = true;
@ -92,6 +97,27 @@ static void reset(int signo) { (void)(signo);
if (jmpflag) { siglongjmp(jmp, 1); }
}
/* Evaluate $XDG_CONFIG_HOME/esh/eshrc file. */
static void eshrc(void) {
char *dir = strdup(getenv("XDG_CONFIG_HOME"));
/* If XDG_CONFIG_HOME is unset or empty, use the default */
if (!dir || !dir[0]) {
char *home = getenv("HOME");
if (!home || !home[0]) { warn("$HOME is unset or empty"); return; }
dir = assert_malloc(strlen(home) + strlen("/.config") + 1);
strcpy(dir, home); strcat(dir, "/.config");
}
char *path, *base = "/esh/eshrc";
path = assert_malloc(strlen(dir) + strlen(base) + 1);
strcpy(path, dir); strcat(path, base); free(dir);
eval_file((u8 *)path); free(path);
}
static void hlp(void) {
puts("ESH - Executive Shell\n");
puts("Usage: esh\n");

Loading…
Cancel
Save