diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..06ac611 --- /dev/null +++ b/.clangd @@ -0,0 +1,3 @@ +CompileFlags: + Add: ["--std=c2x"] + Compiler: gcc diff --git a/CHANGELOG.md b/CHANGELOG.md index 6736147..c1571dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.0.4] - 2025-03-11 ### Added + - Directory-level configuration with `.nutshell.json` files - Configuration hierarchy: directory configs override user configs which override system configs - Automatic config reloading when changing directories with `cd` @@ -15,5 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for different themes per project ### Fixed + - Memory leak in directory path traversal -- Config loading order to properly respect precedence rules \ No newline at end of file +- Config loading order to properly respect precedence rules diff --git a/README.md b/README.md index 90a7c27..2c8b593 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,10 @@ cd nutshell make ``` -### Installing +### Installing #### Via Homebrew (macOS & Linux) + ```bash # If using the formula directly brew install --build-from-source ./nutshell.rb @@ -44,15 +45,19 @@ brew install nutshell ``` #### System-wide installation (requires sudo) + ```bash sudo make install ``` #### User-level installation + ```bash make install-user ``` + Then add `$HOME/bin` to your PATH if it's not already there: + ```bash echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc # or ~/.zshrc or ~/.bash_profile ``` @@ -85,11 +90,13 @@ Nutshell includes AI features to help with shell commands: 1. Get an OpenAI API key from [OpenAI Platform](https://platform.openai.com/) 2. Set your API key: + ```bash 🥜 ~ ➜ set-api-key YOUR_API_KEY ``` - + Alternatively, set it as an environment variable: + ```bash export OPENAI_API_KEY=your_api_key ``` @@ -303,11 +310,13 @@ NUT_DEBUG=1 NUT_DEBUG_THEME=1 NUT_DEBUG_PARSER=1 NUT_DEBUG_EXEC=1 NUT_DEBUG_REGI ## Creating Packages Packages are directories containing: + - `manifest.json`: Package metadata - `[package-name].sh`: Main executable script - Additional files as needed Example manifest.json: + ```json { "name": "mypackage", @@ -320,6 +329,7 @@ Example manifest.json: ``` Generate a checksum for your package with: + ```bash ./scripts/generate_checksum.sh mypackage ``` @@ -370,4 +380,4 @@ nutshell/ ## License -[MIT License](LICENSE) \ No newline at end of file +[MIT License](LICENSE) diff --git a/nutshell.rb b/nutshell.rb index c138bd0..944d094 100644 --- a/nutshell.rb +++ b/nutshell.rb @@ -1,40 +1,42 @@ +# frozen_string_literal: true + class Nutshell < Formula - desc "Enhanced Unix shell with simplified command language and AI assistance" - homepage "https://github.com/chandralegend/nutshell" - url "https://github.com/chandralegend/nutshell/archive/refs/tags/v0.0.4.tar.gz" - sha256 "d3cd4b9b64fb6d657195beb7ea9d47a193ace561d8d54b64e9890304e41c6829" - license "MIT" - head "https://github.com/chandralegend/nutshell.git", branch: "main" + desc 'Enhanced Unix shell with simplified command language and AI assistance' + homepage 'https://github.com/chandralegend/nutshell' + url 'https://github.com/chandralegend/nutshell/archive/refs/tags/v0.0.4.tar.gz' + sha256 'd3cd4b9b64fb6d657195beb7ea9d47a193ace561d8d54b64e9890304e41c6829' + license 'MIT' + head 'https://github.com/chandralegend/nutshell.git', branch: 'main' + + depends_on 'pkg-config' => :build + depends_on 'jansson' + depends_on 'readline' + depends_on 'openssl@3' + depends_on 'curl' - depends_on "pkg-config" => :build - depends_on "jansson" - depends_on "readline" - depends_on "openssl@3" - depends_on "curl" - def install # Pass correct environment variables to find libraries - ENV.append "CFLAGS", "-I#{Formula["jansson"].opt_include}" - ENV.append "LDFLAGS", "-L#{Formula["jansson"].opt_lib} -ljansson" - ENV.append "CFLAGS", "-I#{Formula["openssl@3"].opt_include}" - ENV.append "LDFLAGS", "-L#{Formula["openssl@3"].opt_lib}" - - system "make" - bin.install "nutshell" - + ENV.append 'CFLAGS', "-I#{Formula['jansson'].opt_include}" + ENV.append 'LDFLAGS', "-L#{Formula['jansson'].opt_lib} -ljansson" + ENV.append 'CFLAGS', "-I#{Formula['openssl@3'].opt_include}" + ENV.append 'LDFLAGS', "-L#{Formula['openssl@3'].opt_lib}" + + system 'make' + bin.install 'nutshell' + # Install documentation - doc.install "README.md", "CHANGELOG.md" - + doc.install 'README.md', 'CHANGELOG.md' + # Create themes directory and install themes directly in the Cellar # The themes directory will be in the Formula's prefix, not in /usr/local/share - themes_dir = prefix/"themes" + themes_dir = prefix / 'themes' themes_dir.mkpath - Dir["themes/*.json"].each do |theme_file| + Dir['themes/*.json'].each do |theme_file| themes_dir.install theme_file end - + # Create a nutshell config directory in the Formula's prefix for packages - (prefix/"packages").mkpath + (prefix / 'packages').mkpath end def post_install @@ -42,24 +44,24 @@ def post_install user_config_dir = "#{Dir.home}/.nutshell" user_themes_dir = "#{user_config_dir}/themes" user_packages_dir = "#{user_config_dir}/packages" - - system "mkdir", "-p", user_themes_dir - system "mkdir", "-p", user_packages_dir - + + system 'mkdir', '-p', user_themes_dir + system 'mkdir', '-p', user_packages_dir + # Copy themes to user directory if it doesn't already have them if Dir.exist?(user_themes_dir) && Dir.empty?(user_themes_dir) Dir["#{prefix}/themes/*.json"].each do |theme| - system "cp", theme, user_themes_dir + system 'cp', theme, user_themes_dir end end - + # Print instructions for the user - ohai "Nutshell has been installed!" - opoo "Make sure to set an API key for AI features with: set-api-key YOUR_API_KEY" + ohai 'Nutshell has been installed!' + opoo 'Make sure to set an API key for AI features with: set-api-key YOUR_API_KEY' end test do # Test that nutshell runs without errors (--help should return 0) - assert_match "Nutshell", shell_output("#{bin}/nutshell --help", 0) + assert_match 'Nutshell', shell_output("#{bin}/nutshell --help", 0) end end