Giter Site home page Giter Site logo

Comments (4)

SaidTorres3 avatar SaidTorres3 commented on June 27, 2024 1

Same problem

from ai-shell.

jakenuts avatar jakenuts commented on June 27, 2024 1

Short answer is to call this before ai-shell.

$env:SHELL="Powershell"

Long answer is:

AI-Shell uses execa to execute the generated scripts, and attempts to determine your shell by checking the process.env.SHELL environment variable. On Windows, that's undefined and so it passes "shell:true" which executes cmd.exe. (shell:false also fails so but I didn't dig further).

  • I'm still not satisfied with the short answer though as execa launches a new powershell process (loads your profile, modules, shows messages) which feels like overkill as you were just in a perfectly good Powershell process moments before you typed "ai". Still looking if there is a way to reuse your current shell process but getting sleepy.

from ai-shell.

jakenuts avatar jakenuts commented on June 27, 2024 1

@mefengl Sure, that would likely work. Actually I just found another way suggested by someone on SO. Instead of trying to detect the shell inside the node project, create a ai.cmd and ai.ps1 file and when the user types "ai" each shell will call the one with it's default extension. Turns out, there already is an ai.cmd and ai.ps1 C:\Users{yourname}\AppData\Roaming\npm so you could probably just set the shell variable or pass an argument into the script from there.

image

I bet a clever PowerShell person (definitely not me) could even pass an argument into the ai-shell script to just return the script instead of using execa and (or copy it to the clipboard) then execute that output within the same PowerShell context you started in.

from ai-shell.

mefengl avatar mefengl commented on June 27, 2024

@jakenuts maybe run a PowerShell command to set the env value if it succeeds?

// by gpt4
const child_process = require('child_process');

function isRunningInPowershell() {
    try {
        // Execute a PowerShell-specific command
        child_process.execSync('Get-Process -Id $PID', { stdio: 'ignore' });
        return true;
    } catch (e) {
        return false;
    }
}

if (isRunningInPowershell()) {
    console.log("Running in PowerShell. Setting environment variable.");
    // Set the environment variable
    process.env.SHELL = "Powershell";
    console.log("Environment variable set:", process.env.SHELL);
    // Add any other PowerShell-specific operations here
} else {
    console.log("Not running in PowerShell, perform standard operations.");
    // Add standard operations here
}

from ai-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.