rebrand to 90s

This commit is contained in:
Night Kaly 2024-07-01 17:40:47 +01:00
parent 253ec734f0
commit e4e118046c
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
16 changed files with 83 additions and 80 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
rush
90s
*.o
*.tar.gz

10
90s.1 Normal file
View file

@ -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 <night@night0721.xyz>

View file

@ -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

View file

@ -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/)

View file

@ -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

10
rush.1
View file

@ -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 <night@night0721.xyz>

View file

@ -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);
}
}

View file

@ -2,13 +2,13 @@
#include <string.h>
#include <stdlib.h>
#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);

View file

@ -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;

View file

@ -6,7 +6,7 @@
#include <linux/limits.h>
#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);

View file

@ -2,7 +2,7 @@
#include <stdbool.h>
#include <string.h>
#include "rush.h"
#include "90s.h"
typedef struct job {
pid_t pid;