Comments (4)
Same problem
from ai-shell.
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.
@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.
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.
@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)
- After the first installation, run the sample command, which cannot be run. The screenshot is the error message. HOT 1
- ✖ connect ETIMEDOUT 174.36.228.136:443
- Script doesn't execute because of ``` HOT 3
- Worked a few times, then it stopped HOT 8
- Hope to support custom API_BASE_URL HOT 1
- Feature suggestion: place prompts in a separate text file
- Duplicated response HOT 2
- Add Azure OpenAI support HOT 4
- User can press q to exit HOT 1
- Need a way to edit coloring
- TTY initialization failed: uv_tty_init returned EBADF (bad file descriptor) HOT 1
- Allow users to specify a `-y` argument for not asking to execute the script
- Error 429 makes the program exit.
- Link back Github page in help page so we know where to look for updates 😅 HOT 1
- AI hallucinations HOT 1
- Piping ( | ) to ai HOT 1
- Chat gives empty response HOT 5
- Error when running sudo ai config set OPENAI_KEY=<my openi key goes here> HOT 2
- Is it a good idea to put the run command into shell history? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ai-shell.