Initial commit
This commit is contained in:
commit
18f78db05c
5 changed files with 140 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
nsh
|
||||
*.o
|
||||
*.tar.gz
|
28
LICENSE
Normal file
28
LICENSE
Normal file
|
@ -0,0 +1,28 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2024, Night Kaly <night@night0721.xyz>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
Makefile
Normal file
38
Makefile
Normal file
|
@ -0,0 +1,38 @@
|
|||
.POSIX:
|
||||
.SUFFIXES:
|
||||
|
||||
CC = cc
|
||||
VERSION = 1.0
|
||||
TARGET = nsh
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
||||
# Flags
|
||||
CFLAGS = -O3 -march=native -mtune=native -pipe -s -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
|
||||
|
||||
SRC = $(TARGET).c
|
||||
|
||||
$(TARGET): $(SRC)
|
||||
$(CC) $(SRC) -o $@ $(CFLAGS)
|
||||
|
||||
dist:
|
||||
mkdir -p $(TARGET)-$(VERSION)
|
||||
cp -R README.md $(TARGET) $(TARGET)-$(VERSION)
|
||||
tar -cf $(TARGET)-$(VERSION).tar $(TARGET)-$(VERSION)
|
||||
gzip $(TARGET)-$(VERSION).tar
|
||||
rm -rf $(TARGET)-$(VERSION)
|
||||
|
||||
install: $(TARGET)
|
||||
mkdir -p $(DESTDIR)$(BINDIR)
|
||||
cp -p $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
chmod 755 $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
|
||||
uninstall:
|
||||
$(RM) $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
|
||||
clean:
|
||||
$(RM) $(TARGET)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
.PHONY: all dist install uninstall clean
|
24
README.md
Normal file
24
README.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# nsh
|
||||
Neo Syntax Highlighter
|
||||
|
||||
# Usage
|
||||
```sh
|
||||
git diff | nsh
|
||||
diff <x> <y> | nsh
|
||||
```
|
||||
|
||||
# Dependencies
|
||||
None
|
||||
|
||||
# Building
|
||||
You will need to run these with elevated privilages.
|
||||
```
|
||||
$ make
|
||||
# make install
|
||||
```
|
||||
|
||||
# Contributions
|
||||
Contributions are welcomed, feel free to open a pull request.
|
||||
|
||||
# License
|
||||
This project is licensed under the BSD-3-Clause License. See [LICENSE](https://github.com/night0721/nsh/blob/master/LICENSE) for more information.
|
47
nsh.c
Normal file
47
nsh.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define COLOR_RESET "\033[0m"
|
||||
#define COLOR_TEAL "\033[38;2;148;226;213m"
|
||||
#define COLOR_GREEN "\033[38;2;166;227;161m"
|
||||
#define COLOR_RED "\033[38;2;243;139;168m"
|
||||
#define COLOR_BLUE "\033[38;2;137;180;250m"
|
||||
#define COLOR_PEACH "\033[38;2;250;179;135m"
|
||||
#define COLOR_YELLOW "\033[38;2;249;226;175m"
|
||||
#define COLOR_OVERLAY0 "\033[38;2;108;112;134m"
|
||||
|
||||
#define MAX_LINE_LENGTH 1024
|
||||
|
||||
int main()
|
||||
{
|
||||
char buffer[MAX_LINE_LENGTH];
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
||||
/* Remove newline from buffer, if present */
|
||||
size_t len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
|
||||
if (strncmp(buffer, "---", 3) == 0) {
|
||||
printf(COLOR_YELLOW "%s" COLOR_RESET "\n", buffer);
|
||||
} else if (strncmp(buffer, "+++", 3) == 0) {
|
||||
printf(COLOR_PEACH "%s" COLOR_RESET "\n", buffer);
|
||||
} else if (strncmp(buffer, "@@", 2) == 0) {
|
||||
printf(COLOR_OVERLAY0 "%s" COLOR_RESET "\n", buffer);
|
||||
} else if (strncmp(buffer, "index", 5) == 0) {
|
||||
printf(COLOR_TEAL "%s" COLOR_RESET "\n", buffer);
|
||||
} else if (strncmp(buffer, "diff", 4) == 0) {
|
||||
printf(COLOR_BLUE "%s" COLOR_RESET "\n", buffer);
|
||||
} else if (buffer[0] == '+') {
|
||||
printf(COLOR_GREEN "%s" COLOR_RESET "\n", buffer);
|
||||
} else if (buffer[0] == '-') {
|
||||
printf(COLOR_RED "%s" COLOR_RESET "\n", buffer);
|
||||
} else {
|
||||
printf("%s\n", buffer);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in a new issue