Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ on:

jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install cmake
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y cmake
Expand Down
30 changes: 27 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,44 @@ permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
build:
strategy:
matrix:
include:
- os: ubuntu-latest
asset: trigger-linux-x86_64
- os: macos-latest
asset: trigger-macos-arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install cmake
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y cmake
- name: Build (Release)
run: |
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build --target shell
cp build/shell ${{ matrix.asset }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset }}
path: ${{ matrix.asset }}

# One publishing job so the matrix builds don't race to create the release
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: build/shell
files: |
trigger-linux-x86_64
trigger-macos-arm64
generate_release_notes: true
16 changes: 10 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ Lint (also enforced in CI as a separate `lint` job, see below):
cmake -B cmake-build-debug -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
clang-tidy -p cmake-build-debug -warnings-as-errors=* $(find src include -name '*.c')

CI (`.github/workflows/ci.yml`) runs on every PR and push to `main` with two jobs:
`build-and-test` (`./run_tests.sh`) and `lint` (clang-format + clang-tidy, both
warnings-as-errors). Formatting follows `.clang-format` (LLVM base, 4-space indent,
100 col limit); tidy checks are configured in `.clang-tidy`. A tag matching `v*.*.*`
triggers `.github/workflows/release.yml`, which builds a Release binary and attaches
it to a GitHub release.
CI (`.github/workflows/ci.yml`) runs on every PR and push to `main` with three jobs:
`build-and-test` (`./run_tests.sh` on both `ubuntu-latest` and `macos-latest`),
`sanitize` (ASan/UBSan, Linux only) and `lint` (clang-format + clang-tidy, both
warnings-as-errors). Tests must stay portable across Linux and macOS: don't hardcode
binaries that differ between them (e.g. use `true`, not `/bin/true`), and remember that
`/tmp` resolves to `/private/tmp` on macOS. Formatting follows `.clang-format` (LLVM
base, 4-space indent, 100 col limit); tidy checks are configured in `.clang-tidy`. A tag matching `v*.*.*`
triggers `.github/workflows/release.yml`, which builds Release binaries on Linux and
macOS and attaches them to a GitHub release as `trigger-linux-x86_64` and
`trigger-macos-arm64`.

## Architecture

Expand Down
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set(LIB_SOURCES
src/builtins.c
src/pipeline.c
src/glob.c
src/nepeta.c
)

set(UTIL_SOURCES
Expand All @@ -24,7 +23,6 @@ set(HEADERS
include/builtins.h
include/pipeline.h
include/glob_expand.h
include/nepeta.h
)

add_library(trigger_core STATIC ${LIB_SOURCES} ${UTIL_SOURCES})
Expand Down Expand Up @@ -69,13 +67,8 @@ target_link_libraries(test_glob trigger_core)
target_compile_options(test_glob PRIVATE -Wall -Wextra -Werror)
add_test(NAME GlobTests COMMAND test_glob)

add_executable(test_nepeta tests/test_nepeta.c)
target_link_libraries(test_nepeta trigger_core)
target_compile_options(test_nepeta PRIVATE -Wall -Wextra -Werror)
add_test(NAME NepetaTests COMMAND test_nepeta)

add_custom_target(run_tests
COMMAND ${CMAKE_CTEST_COMMAND} --verbose
DEPENDS test_input test_builtins test_execute test_pipeline test_glob test_nepeta
DEPENDS test_input test_builtins test_execute test_pipeline test_glob
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

This project aims to create a clean, efficient shell.

## Platforms

Trigger targets POSIX systems: Linux and macOS are built and tested in CI, and tagged
releases ship `trigger-linux-x86_64` and `trigger-macos-arm64` binaries. Windows is not
supported natively (the shell relies on `fork`, `execvp`, `pipe` and `glob`); use WSL,
MSYS2 or Cygwin there.

## Building

```bash
Expand Down
1 change: 0 additions & 1 deletion include/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ int trigger_pwd(char **args);
int trigger_echo(char **args);
int trigger_export(char **args);
int trigger_unset(char **args);
int trigger_nepeta(char **args);

int trigger_num_builtins(void);
const Builtin *find_builtin(const char *name);
Expand Down
16 changes: 0 additions & 16 deletions include/nepeta.h

This file was deleted.

53 changes: 9 additions & 44 deletions src/builtins.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include "builtins.h"
#include "nepeta.h"
#include "utils/utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static const Builtin builtins[] = {
{"cd", trigger_cd}, {"help", trigger_help}, {"exit", trigger_exit},
{"pwd", trigger_pwd}, {"echo", trigger_echo}, {"export", trigger_export},
{"unset", trigger_unset}, {"nepeta", trigger_nepeta},
{"cd", trigger_cd}, {"help", trigger_help}, {"exit", trigger_exit},
{"pwd", trigger_pwd}, {"echo", trigger_echo}, {"export", trigger_export},
{"unset", trigger_unset},
};

static const int builtin_count = sizeof(builtins) / sizeof(builtins[0]);
Expand All @@ -27,7 +26,7 @@ const Builtin *find_builtin(const char *name) {

int trigger_cd(char **args) {
if (args[1] == NULL) {
trigger_nepeta_say(stderr, "trigger: expected argument to \"cd\"\n");
fprintf(stderr, "trigger: expected argument to \"cd\"\n");
return 1;
}
if (chdir(args[1]) != 0) {
Expand All @@ -39,15 +38,15 @@ int trigger_cd(char **args) {
}

int trigger_help(char **args __attribute__((unused))) {
trigger_nepeta_say(stdout, "Trigger: A simple shell written in C\n");
trigger_nepeta_say(stdout, "Type program names and arguments, and hit enter.\n");
trigger_nepeta_say(stdout, "The following are built in:\n");
printf("Trigger: A simple shell written in C\n");
printf("Type program names and arguments, and hit enter.\n");
printf("The following are built in:\n");

for (int i = 0; i < builtin_count; i++) {
printf(" %s\n", builtins[i].name);
}

trigger_nepeta_say(stdout, "Use the man command for information on other programs.\n");
printf("Use the man command for information on other programs.\n");
return 0;
}

Expand All @@ -58,9 +57,7 @@ int trigger_exit(char **args) {
if (*endptr == '\0' && n >= 0 && n <= 255) {
return (int) n;
}
char buf[256];
snprintf(buf, sizeof(buf), "trigger: exit: %s: numeric argument required\n", args[1]);
trigger_nepeta_say(stderr, buf);
fprintf(stderr, "trigger: exit: %s: numeric argument required\n", args[1]);
return 2;
}
return EXIT_SUCCESS;
Expand Down Expand Up @@ -117,35 +114,3 @@ int trigger_unset(char **args) {
}
return 0;
}

int trigger_nepeta(char **args) {
if (args[1] == NULL) {
trigger_nepeta_set_enabled(!trigger_nepeta_is_enabled());
trigger_nepeta_say(stdout, "Nepeta mode toggled.\n");
return 0;
}

if (strcmp(args[1], "on") == 0) {
trigger_nepeta_set_enabled(true);
trigger_nepeta_say(stdout, "Nepeta mode enabled.\n");
return 0;
}

if (strcmp(args[1], "off") == 0) {
trigger_nepeta_set_enabled(false);
trigger_nepeta_say(stdout, "Nepeta mode disabled.\n");
return 0;
}

if (strcmp(args[1], "status") == 0) {
if (trigger_nepeta_is_enabled()) {
trigger_nepeta_say(stdout, "Nepeta mode is enabled.\n");
} else {
trigger_nepeta_say(stdout, "Nepeta mode is disabled.\n");
}
return 0;
}

trigger_nepeta_say(stderr, "usage: nepeta [on|off|status]\n");
return 1;
}
6 changes: 1 addition & 5 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "execute.h"
#include "input.h"
#include "nepeta.h"
#include "utils/utils.h"
#include <signal.h>
#include <stdbool.h>
Expand All @@ -11,7 +10,7 @@ void trigger_loop(void) {
int last_status = 0;

for (;;) {
printf("%s", trigger_nepeta_prompt());
printf("> ");
fflush(stdout);
char *line = trigger_read_line();
TokenList *tl = parse_line_with_quotes(line);
Expand Down Expand Up @@ -39,9 +38,6 @@ int main(void) {
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);

trigger_nepeta_init_from_env();
trigger_nepeta_print_banner();

trigger_loop();

return EXIT_SUCCESS;
Expand Down
Loading
Loading