You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Name: Install with Homebrew// Description: Install a package using Homebrew// Author: Nickolas Høyer-Larsen// Version: 1.0import{execasexecRaw}from"node:child_process";import{promisify}from"node:util";import"@johnlindquist/kit";constexec=promisify(execRaw);typeInfoType={name?: string;description?: string;version?: string;fromUrl?: string;projectUrl?: string;analytics?: string;artifacts?: string;installed?: boolean;};constextractExtraDetails=(input)=>({version: (input.match(/==> [\w\s]+: ([\d.]+)/i)||[null])[1]||null,fromUrl: (input.match(/From: (https?:\/\/[^\s]+)/i)||[null])[1]||null,projectUrl: (input.match(/https?:\/\/[^\s]+/i)||[])[0]||null,installed: !input.includes("Not installed")});functionparseToJSON(input): InfoType{constresult=input.split("\n").reduce((acc,line)=>{if(line.startsWith("==>")){acc.currentKey=line.replace("==>","").trim().toLowerCase();acc[acc.currentKey]="";}elseif(acc.currentKey){acc[acc.currentKey]+=` ${line.trim()}`;}returnacc;},{});Object.keys(result).forEach(key=>{result[key]=result[key].trim();});return{ ...result, ...extractExtraDetails(input)};}constpackageName=awaitarg("Package name",div(` <h1>Install a Homebrew Package</h1> <p class="text-sm font-normal">Enter the name of the package you want to install.<br> You will see package details and be asked for confirmation before the installation proceeds.</p>`,"p-4"));const{stdout: infoStdOut}=awaitexec(`PATH="/opt/homebrew/bin:$PATH" brew info ${packageName}`,);constinfo=parseToJSON(infoStdOut);if(info.installed){setTimeout(()=>{exit();},3000);awaitdiv(md(`## Package is already installed. Exiting in 3 seconds...`));}constshouldInstall=awaitdiv({html: `${info.name ? `<h1><strong>${info.name}</strong> (${info.version})</h1>` : ""}${info.version ? `<a href="${info.projectUrl}">${info.projectUrl}</a>` : ""}${info.description ? `<p>${info.description}</p>` : ""}${info.fromUrl ? `<p><strong>From:</strong> ${info.fromUrl}</p>` : ""}${md(`### Do you want to install this package?* [Yes](submit:yes)* [No](submit:no)`)}`.trim(),},"p-8",);if(shouldInstall==="yes"){awaitterm(`PATH="/opt/homebrew/bin:$PATH" brew install ${packageName} && exit`,);setTimeout(()=>{exit();},3000);awaitdiv(md(`## Package has been succesfully installed!Exiting in 3 seconds...`));}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Open install-with-homebrew in Script Kit
Beta Was this translation helpful? Give feedback.
All reactions