diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 6e9506c..bf1c66e 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,7 @@ Mkfile.old dkms.conf build -vcpkg_installed \ No newline at end of file +vcpkg_installed + +# nix +.direnv diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b48436d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 0xViena + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5261a7a --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1772433332, + "narHash": "sha256-izhTDFKsg6KeVBxJS9EblGeQ8y+O8eCa6RcW874vxEc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "cf59864ef8aa2e178cccedbe2c178185b0365705", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5e04212 --- /dev/null +++ b/flake.nix @@ -0,0 +1,25 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.${system}.default = pkgs.mkShell { + packages = with pkgs; [ + gnumake42 + libgcc + clang-tools + readline + ]; + }; + }; +} + diff --git a/include/helpers/prompt.h b/include/helpers/prompt.h new file mode 100644 index 0000000..5f6d054 --- /dev/null +++ b/include/helpers/prompt.h @@ -0,0 +1,6 @@ +#ifndef PROMPT_H +#define PROMPT_H + +char *build_prompt(void); + +#endif \ No newline at end of file diff --git a/src/helpers/prompt.c b/src/helpers/prompt.c new file mode 100644 index 0000000..133bfcd --- /dev/null +++ b/src/helpers/prompt.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +char *build_prompt(void) { + char *cwd = getcwd(NULL, 0); + if (!cwd) + return NULL; + + size_t len = strlen(cwd) + 4; + char *prompt = malloc(len); + if (!prompt) { + free(cwd); + return NULL; + } + + snprintf(prompt, len, "%s $ ", cwd); + free(cwd); + return prompt; +} diff --git a/src/main.c b/src/main.c index 900f963..3f8367e 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include "../include/builtins/shell_builtin.h" #include "../include/helpers/free_pipeline.h" #include "../include/helpers/hashmap.h" +#include "../include/helpers/prompt.h" #include "../include/init_auto_completion.h" #include "../include/load_history.h" #include "../include/parser/parser.h" @@ -29,7 +30,10 @@ int main() { while (1) { - char *line = readline("$ "); + char *prompt = build_prompt(); + char *line = readline(prompt); + free(prompt); + if (!line) break; diff --git a/src/run/pipeline.c b/src/run/pipeline.c index 5808fe1..b50d2dd 100644 --- a/src/run/pipeline.c +++ b/src/run/pipeline.c @@ -10,7 +10,10 @@ int run_pipeline(pipeline_t *pl) { for (size_t i = 0; i < pl->count; i++) { if (i < pl->count - 1) - pipe(pfds); + if (-1 == pipe(pfds)) { + perror("pipe"); + return -1; + } pc cmd = pl->commands[i]; pid_t pid = fork();