|
| 1 | +class Nutshell < Formula |
| 2 | + desc "Enhanced Unix shell with simplified command language and AI assistance" |
| 3 | + homepage "https://github.com/chandralegend/nutshell" |
| 4 | + url "https://github.com/chandralegend/nutshell/archive/refs/tags/v0.0.4.tar.gz" |
| 5 | + sha256 "d3cd4b9b64fb6d657195beb7ea9d47a193ace561d8d54b64e9890304e41c6829" |
| 6 | + license "MIT" |
| 7 | + head "https://github.com/chandralegend/nutshell.git", branch: "main" |
| 8 | + |
| 9 | + depends_on "pkg-config" => :build |
| 10 | + depends_on "jansson" |
| 11 | + depends_on "readline" |
| 12 | + depends_on "openssl@3" |
| 13 | + depends_on "curl" |
| 14 | + |
| 15 | + def install |
| 16 | + # Pass correct environment variables to find libraries |
| 17 | + ENV.append "CFLAGS", "-I#{Formula["jansson"].opt_include}" |
| 18 | + ENV.append "LDFLAGS", "-L#{Formula["jansson"].opt_lib} -ljansson" |
| 19 | + ENV.append "CFLAGS", "-I#{Formula["openssl@3"].opt_include}" |
| 20 | + ENV.append "LDFLAGS", "-L#{Formula["openssl@3"].opt_lib}" |
| 21 | + |
| 22 | + system "make" |
| 23 | + bin.install "nutshell" |
| 24 | + |
| 25 | + # Install documentation |
| 26 | + doc.install "README.md", "CHANGELOG.md" |
| 27 | + |
| 28 | + # Create themes directory and install themes directly in the Cellar |
| 29 | + # The themes directory will be in the Formula's prefix, not in /usr/local/share |
| 30 | + themes_dir = prefix/"themes" |
| 31 | + themes_dir.mkpath |
| 32 | + Dir["themes/*.json"].each do |theme_file| |
| 33 | + themes_dir.install theme_file |
| 34 | + end |
| 35 | + |
| 36 | + # Create a nutshell config directory in the Formula's prefix for packages |
| 37 | + (prefix/"packages").mkpath |
| 38 | + end |
| 39 | + |
| 40 | + def post_install |
| 41 | + # Create ~/.nutshell directory structure for the user if it doesn't exist |
| 42 | + user_config_dir = "#{Dir.home}/.nutshell" |
| 43 | + user_themes_dir = "#{user_config_dir}/themes" |
| 44 | + user_packages_dir = "#{user_config_dir}/packages" |
| 45 | + |
| 46 | + system "mkdir", "-p", user_themes_dir |
| 47 | + system "mkdir", "-p", user_packages_dir |
| 48 | + |
| 49 | + # Copy themes to user directory if it doesn't already have them |
| 50 | + if Dir.exist?(user_themes_dir) && Dir.empty?(user_themes_dir) |
| 51 | + Dir["#{prefix}/themes/*.json"].each do |theme| |
| 52 | + system "cp", theme, user_themes_dir |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + # Print instructions for the user |
| 57 | + ohai "Nutshell has been installed!" |
| 58 | + opoo "Make sure to set an API key for AI features with: set-api-key YOUR_API_KEY" |
| 59 | + end |
| 60 | + |
| 61 | + test do |
| 62 | + # Test that nutshell runs without errors (--help should return 0) |
| 63 | + assert_match "Nutshell", shell_output("#{bin}/nutshell --help", 0) |
| 64 | + end |
| 65 | +end |
0 commit comments