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
3 changes: 3 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CompileFlags:
Add: ["--std=c2x"]
Compiler: gcc
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ 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`
- Project-specific aliases and settings through directory configs
- Support for different themes per project

### Fixed

- Memory leak in directory path traversal
- Config loading order to properly respect precedence rules
- Config loading order to properly respect precedence rules
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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",
Expand All @@ -320,6 +329,7 @@ Example manifest.json:
```

Generate a checksum for your package with:

```bash
./scripts/generate_checksum.sh mypackage
```
Expand Down Expand Up @@ -370,4 +380,4 @@ nutshell/

## License

[MIT License](LICENSE)
[MIT License](LICENSE)
72 changes: 37 additions & 35 deletions nutshell.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
# 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
# Create ~/.nutshell directory structure for the user if it doesn't exist
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