From ae33a373df1ee4898f561e21390e1b3c127825a5 Mon Sep 17 00:00:00 2001 From: Viena <169875752+devnchill@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:37:48 +0530 Subject: [PATCH 1/5] fix: check return value of pipe to return incase of error --- src/run/pipeline.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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(); From 7b04b40a10163f39900216dbeffc76eebc597a44 Mon Sep 17 00:00:00 2001 From: Viena <169875752+devnchill@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:37:58 +0530 Subject: [PATCH 2/5] chore: add devshell for nix os --- .envrc | 1 + .gitignore | 5 ++++- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 25 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix 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/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 + ]; + }; + }; +} + From a37e12b2c1204dad64fc708fc2b57be37e2dd9ae Mon Sep 17 00:00:00 2001 From: darshan Date: Tue, 3 Mar 2026 15:12:55 +0530 Subject: [PATCH 3/5] feat: display current working directly in prompt --- include/helpers/prompt.h | 6 ++++++ src/helpers/prompt.c | 21 +++++++++++++++++++++ src/main.c | 6 +++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 include/helpers/prompt.h create mode 100644 src/helpers/prompt.c 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..bde348d --- /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; +} \ No newline at end of file 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; From 5381dcf916fd29859c2052acbf2e3481c6fe577b Mon Sep 17 00:00:00 2001 From: 0xViena <169875752+devnchill@users.noreply.github.com> Date: Tue, 3 Mar 2026 15:42:08 +0530 Subject: [PATCH 4/5] Add MIT License to the project --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE 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. From 7fb99495ea97995588d78a96f8c9ff608ae60bec Mon Sep 17 00:00:00 2001 From: 0xViena <169875752+devnchill@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:41:19 +0530 Subject: [PATCH 5/5] style: format with clang-format --- src/helpers/prompt.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/helpers/prompt.c b/src/helpers/prompt.c index bde348d..133bfcd 100644 --- a/src/helpers/prompt.c +++ b/src/helpers/prompt.c @@ -1,21 +1,21 @@ -#include +#include #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; - } + char *cwd = getcwd(NULL, 0); + if (!cwd) + return NULL; - snprintf(prompt, len, "%s $ ", cwd); + size_t len = strlen(cwd) + 4; + char *prompt = malloc(len); + if (!prompt) { free(cwd); - return prompt; -} \ No newline at end of file + return NULL; + } + + snprintf(prompt, len, "%s $ ", cwd); + free(cwd); + return prompt; +}