diff --git a/.gitignore b/.gitignore index 3e1d081..9d98a68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -rush +90s *.o *.tar.gz diff --git a/90s.1 b/90s.1 new file mode 100644 index 0000000..f922104 --- /dev/null +++ b/90s.1 @@ -0,0 +1,10 @@ +.TH 90s 1 90s\-VERSION +.SH NAME +90s \- the 90s shell +.SH SYNOPSIS +.B 90s +.SH DESCRIPTION +90s is a shell that is heavily customized, minimalistic, simple but with several features. That includes simple syntax highlighting for showing validity of commands with history search and support of environment varaibles. +.SH AUTHOR +Made by Night Kaly +.B diff --git a/Makefile b/Makefile index 106435b..94c8446 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,45 @@ -CC=gcc +.POSIX: +.SUFFIXES: +CC = cc VERSION = 1.0 -PREFIX = /usr/local -MANPREFIX = ${PREFIX}/share/man +TARGET = 90s +MANPAGE = $(TARGET).1 +PREFIX ?= /usr/local +BINDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/share/man/man1 -CFLAGS = -std=gnu11 -O0 -Wall -DVERSION=\"${VERSION}\" +# Flags +CFLAGS = -O3 -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DVERSION=$(VERSION) -SRC = rush.c color.c constants.h history.c commands.c job.c -OBJ = ${SRC:.c=.o} +SRC = src/*.c +INCLUDE = include -.c.o: - ${CC} -c ${CFLAGS} $< - -rush: ${OBJ} - ${CC} -o $@ ${OBJ} - strip rush - -clean: - rm -rf rush +$(TARGET): $(SRC) + $(CC) $(SRC) -o $@ $(CFLAGS) -I$(INCLUDE) dist: - mkdir -p rush-${VERSION} - cp -R LICENSE README.md rush.1 rush rush-${VERSION} - tar -cf rush-${VERSION}.tar rush-${VERSION} - gzip rush-${VERSION}.tar - rm -rf rush-${VERSION} + mkdir -p $(TARGET)-$(VERSION) + cp -R README.md $(MANPAGE) $(TARGET) $(TARGET)-$(VERSION) + tar -cf $(TARGET)-$(VERSION).tar $(TARGET)-$(VERSION) + gzip $(TARGET)-$(VERSION).tar + rm -rf $(TARGET)-$(VERSION) -install: all - mkdir -p ${DESTDIR}${PREFIX}/bin - cp -f rush ${DESTDIR}${PREFIX}/bin - chmod 755 ${DESTDIR}${PREFIX}/bin/rush - mkdir -p ${DESTDIR}${MANPREFIX}/man1 - sed "s/VERSION/${VERSION}/g" < rush.1 > ${DESTDIR}${MANPREFIX}/man1/rush.1 - chmod 644 ${DESTDIR}${MANPREFIX}/man1/rush.1 +install: $(TARGET) + mkdir -p $(DESTDIR)$(BINDIR) + mkdir -p $(DESTDIR)$(MANDIR) + cp -p $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET) + chmod 755 $(DESTDIR)$(BINDIR)/$(TARGET) + cp -p $(MANPAGE) $(DESTDIR)$(MANDIR)/$(MANPAGE) + chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE) uninstall: - rm -f ${DESTDIR}${PREFIX}/bin/rush\ - ${DESTDIR}${MANPREFIX}/man1/rush.1 -all: rush + $(RM) $(DESTDIR)$(BINDIR)/$(TARGET) + $(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE) -.PHONY: all clean dist install uninstall rush +clean: + $(RM) $(TARGET) + +all: $(TARGET) + +.PHONY: all dist install uninstall clean diff --git a/README.md b/README.md index 9a0f35d..8bf4316 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rush +# 90s Minimalist, customizable shell with syntax highlighting. * Disclaimer: This project is for me to learn to write Unix syscalls, code might be inefficient, feel free to point out the mistakes and open a issue for that! @@ -37,7 +37,7 @@ Minimalist, customizable shell with syntax highlighting. # Usage ```sh -$ ./rush +$ ./90s # > to redirect stdout # < to redirect stdin @@ -66,7 +66,7 @@ $ make Contributions are welcomed, feel free to open a pull request. # License -This project is licensed under the GNU Public License v3.0. See [LICENSE](https://github.com/night0721/rush/blob/master/LICENSE) for more information. +This project is licensed under the GNU Public License v3.0. See [LICENSE](https://github.com/night0721/90s/blob/master/LICENSE) for more information. # Credits - [Tutorial - Write a shell in C](https://brennan.io/2015/01/16/write-a-shell-in-c/) diff --git a/rush.h b/include/90s.h similarity index 100% rename from rush.h rename to include/90s.h diff --git a/color.h b/include/color.h similarity index 100% rename from color.h rename to include/color.h diff --git a/commands.h b/include/commands.h similarity index 100% rename from commands.h rename to include/commands.h diff --git a/constants.h b/include/constants.h similarity index 90% rename from constants.h rename to include/constants.h index f630f35..2f4d63f 100644 --- a/constants.h +++ b/include/constants.h @@ -1,7 +1,7 @@ #ifndef CONSTANTS_H_ #define CONSTANTS_H_ -#define HISTFILE ".rush_history" // history file name +#define HISTFILE ".90s_history" // history file name #define TOK_BUFSIZE 64 // buffer size of each token #define RL_BUFSIZE 1024 // size of each command #define TOK_DELIM " \t\r\n\a" // delimiter for token diff --git a/history.h b/include/history.h similarity index 100% rename from history.h rename to include/history.h diff --git a/job.h b/include/job.h similarity index 100% rename from job.h rename to include/job.h diff --git a/rush.1 b/rush.1 deleted file mode 100644 index 772b425..0000000 --- a/rush.1 +++ /dev/null @@ -1,10 +0,0 @@ -.TH rush 1 rush\-VERSION -.SH NAME -rush \- the rush shell -.SH SYNOPSIS -.B rush -.SH DESCRIPTION -rush is a shell that is heavily customized, minimalistic, simple but with several features. That includes simple syntax highlighting for showing validity of commands with history search and support of environment varaibles. -.SH AUTHOR -Made by Night Kaly -.B diff --git a/rush.c b/src/90s.c similarity index 97% rename from rush.c rename to src/90s.c index 8c2574b..a6cac0d 100644 --- a/rush.c +++ b/src/90s.c @@ -17,7 +17,7 @@ void *memalloc(size_t size) { void *ptr = malloc(size); if (!ptr) { - fputs("rush: Error allocating memory\n", stderr); + fputs("90s: Error allocating memory\n", stderr); exit(EXIT_FAILURE); } return ptr; @@ -38,7 +38,7 @@ void change_terminal_attribute(int option) { char **setup_path_variable() { char *envpath = getenv("PATH"); if (envpath == NULL) { - fprintf(stderr, "rush: PATH environment variable is missing\n"); + fprintf(stderr, "90s: PATH environment variable is missing\n"); exit(EXIT_FAILURE); } char *path_cpy = memalloc(sizeof(char) * (strlen(envpath) + 1)); @@ -178,7 +178,7 @@ char *readline(char **paths) { if (last_command_len > replace_len) { buffer = realloc(buffer, buffer_len + last_command_len - replace_len + 1); if (!buffer) { - fprintf(stderr, "rush: Error allocating memory\n"); + fprintf(stderr, "90s: Error allocating memory\n"); exit(EXIT_FAILURE); } } @@ -335,7 +335,7 @@ char *readline(char **paths) { bufsize += RL_BUFSIZE; buffer = realloc(buffer, bufsize); if (!buffer) { - fprintf(stderr, "rush: Error allocating memory\n"); + fprintf(stderr, "90s: Error allocating memory\n"); exit(EXIT_FAILURE); } } @@ -357,7 +357,7 @@ char **argsplit(char *line) { bufsize += TOK_BUFSIZE; tokens = realloc(tokens, bufsize * sizeof(char*)); if (!tokens) { - fprintf(stderr, "rush: Error allocating memory\n"); + fprintf(stderr, "90s: Error allocating memory\n"); exit(EXIT_FAILURE); } } diff --git a/color.c b/src/color.c similarity index 86% rename from color.c rename to src/color.c index 56845a0..ae7a1ae 100644 --- a/color.c +++ b/src/color.c @@ -2,13 +2,13 @@ #include #include -#include "rush.h" +#include "90s.h" // color str in place char *color_text(char *str, const char *color) { int size = snprintf(NULL, 0, "\x1b[38;2;%sm%s\x1b[0m", color, str) + 1; // calculate size that is needed for colored string if (size < 0) { - fprintf(stderr, "rush: snprintf failed\n"); + fprintf(stderr, "90s: snprintf failed\n"); exit(EXIT_FAILURE); } char *buf = memalloc(size); diff --git a/commands.c b/src/commands.c similarity index 91% rename from commands.c rename to src/commands.c index 03eba59..5941c02 100644 --- a/commands.c +++ b/src/commands.c @@ -8,7 +8,7 @@ #include "constants.h" #include "history.h" -#include "rush.h" +#include "90s.h" #include "job.h" int execute(char **args); @@ -47,13 +47,13 @@ int (*builtin_func[]) (char **) = { }; char *shortcut_dirs[] = { - "rush", + "90s", "bin", "localbin", }; char *shortcut_expand_dirs[] = { - "~/.nky/Coding/C/rush", + "~/.nky/Coding/C/90s", "~/.local/bin", "/usr/local/bin", }; @@ -125,7 +125,7 @@ int num_builtins() { // autojump int j(char **args) { if (args[1] == NULL) { - fprintf(stderr, "rush: not enough arguments\n"); + fprintf(stderr, "90s: not enough arguments\n"); return -1; } for (int i = 0; i < sizeof(shortcut_dirs) / sizeof(char *); i++) { @@ -149,7 +149,7 @@ int cd(char **args) { if (args[1] == NULL) { char *home = gethome(); if (chdir(home) != 0) { - perror("rush"); + perror("90s"); } } else { while (args[1][i] != '\0') { @@ -160,7 +160,7 @@ int cd(char **args) { i++; } if (chdir(args[1]) != 0) { - perror("rush"); + perror("90s"); } } return 1; @@ -168,7 +168,7 @@ int cd(char **args) { // show help menu int help(char **args) { - printf("rush %s\n", VERSION); + printf("90s %s\n", VERSION); printf("Built in commands:\n"); for (int i = 0; i < num_builtins(); i++) { @@ -203,11 +203,11 @@ int export(char **args) { char *value = strtok(NULL, "=\n"); if (variable != NULL && value != NULL) { if (setenv(variable, value, 1) != 0) { - fprintf(stderr, "rush: Error setting environment variable\n"); + fprintf(stderr, "90s: Error setting environment variable\n"); return 0; } } else { - fprintf(stderr, "rush: Syntax error when setting environment variable\nUse \"export VARIABLE=VALUE\"\n"); + fprintf(stderr, "90s: Syntax error when setting environment variable\nUse \"export VARIABLE=VALUE\"\n"); return 0; } args++; @@ -217,14 +217,14 @@ int export(char **args) { int source(char **args) { if (args[1] == NULL) { - fprintf(stderr, "rush: not enough arguments\n"); + fprintf(stderr, "90s: not enough arguments\n"); return -1; } FILE *file = fopen(args[1], "r"); if (file == NULL) { - fprintf(stderr, "rush: no such file or directory '%s'\n", args[1]); + fprintf(stderr, "90s: no such file or directory '%s'\n", args[1]); return -1; } @@ -247,17 +247,17 @@ int source(char **args) { int bg(char **args) { if (args[1] == NULL) { - fprintf(stderr, "rush: not enough arguments\n"); + fprintf(stderr, "90s: not enough arguments\n"); return -1; } int job_index = atoi(args[1]); if (job_index == 0) { - fprintf(stderr, "rush: invalid job index\n"); + fprintf(stderr, "90s: invalid job index\n"); return -1; } job *search = get_job(job_index - 1); if (search == NULL) { - fprintf(stderr, "rush: no such job\n"); + fprintf(stderr, "90s: no such job\n"); return -1; } printf("Job %i: %s\n", job_index, search->command); @@ -287,24 +287,24 @@ int launch(char **args, int fd, int options) { // not stdin, stdout, or stderr if (redirect_stdout) { if (dup2(fd, STDOUT_FILENO) == -1) { - perror("rush"); + perror("90s"); } } if (redirect_stdin) { if (dup2(fd, STDIN_FILENO) == -1) { - perror("rush"); + perror("90s"); } } if (redirect_stderr) { if (dup2(fd, STDERR_FILENO) == -1) { - perror("rush"); + perror("90s"); } } close(fd); // close fd as it is duplicated already } if (execvp(args[0], args) == -1) { if (errno == ENOENT) { - fprintf(stderr, "rush: command not found: %s\n", args[0]); + fprintf(stderr, "90s: command not found: %s\n", args[0]); } } exit(EXIT_FAILURE); // exit the child @@ -351,7 +351,7 @@ int execute(char **args) { if (strncmp(args[num_arg], ">", 1) == 0) { int fd = fileno(fopen(args[num_arg + 1], "w+")); if (fd == -1) { - perror("rush"); + perror("90s"); return 1; } args[num_arg] = NULL; @@ -366,7 +366,7 @@ int execute(char **args) { if (strncmp(args[num_arg], "<", 1) == 0) { int fd = fileno(fopen(args[num_arg + 1], "r")); if (fd == -1) { - perror("rush"); + perror("90s"); return 1; } args[num_arg] = NULL; @@ -375,7 +375,7 @@ int execute(char **args) { if (strncmp(args[num_arg], "2>", 2) == 0) { int fd = fileno(fopen(args[num_arg + 1], "w+")); if (fd == -1) { - perror("rush"); + perror("90s"); return 1; } args[num_arg] = NULL; @@ -384,7 +384,7 @@ int execute(char **args) { if (strncmp(args[num_arg], ">&", 2) == 0) { int fd = fileno(fopen(args[num_arg + 1], "w+")); if (fd == -1) { - perror("rush"); + perror("90s"); return 1; } args[num_arg] = NULL; @@ -393,7 +393,7 @@ int execute(char **args) { if (strncmp(args[num_arg], ">>", 2) == 0) { int fd = fileno(fopen(args[num_arg + 1], "a+")); if (fd == -1) { - perror("rush"); + perror("90s"); return 1; } args[num_arg] = NULL; diff --git a/history.c b/src/history.c similarity index 95% rename from history.c rename to src/history.c index d7e1c63..abe87a3 100644 --- a/history.c +++ b/src/history.c @@ -6,7 +6,7 @@ #include #include "history.h" -#include "rush.h" +#include "90s.h" #include "constants.h" FILE *history_file; @@ -16,7 +16,7 @@ int cmd_count = 0; FILE *open_history_file(char *mode) { history_file = fopen(histfile_path, mode); if (history_file == NULL) { - fprintf(stderr, "rush: Error opening history file\n"); + fprintf(stderr, "90s: Error opening history file\n"); exit(EXIT_FAILURE); } return history_file; @@ -29,7 +29,7 @@ void check_history_file() { env_home = getenv("HOME"); } if (env_home == NULL) { - fprintf(stderr, "rush: HOME AND XDG_CONFIG_HOME environment variable is missing\n"); + fprintf(stderr, "90s: HOME AND XDG_CONFIG_HOME environment variable is missing\n"); exit(EXIT_FAILURE); } int env_home_len = strlen(env_home); diff --git a/job.c b/src/job.c similarity index 98% rename from job.c rename to src/job.c index eb96191..5fc0bc4 100644 --- a/job.c +++ b/src/job.c @@ -2,7 +2,7 @@ #include #include -#include "rush.h" +#include "90s.h" typedef struct job { pid_t pid;