Skip to content

Commit

Permalink
fix issue with listing dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvadratni committed Feb 6, 2025
1 parent 5a1883f commit 99dfb87
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions crates/goose-mcp/src/developer/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,11 @@ pub struct ShellConfig {
impl Default for ShellConfig {
fn default() -> Self {
if cfg!(windows) {
// Prefer PowerShell over cmd.exe for better functionality
if std::process::Command::new("powershell.exe")
.arg("-Command")
.arg("exit")
.output()
.is_ok()
{
Self {
executable: "powershell.exe".to_string(),
arg: "-Command".to_string(),
redirect_syntax: "2>&1".to_string(), // PowerShell supports Unix-style redirection
}
} else {
Self {
executable: "cmd.exe".to_string(),
arg: "/C".to_string(),
redirect_syntax: "2>&1".to_string(), // cmd.exe also supports this syntax
}
// Use cmd.exe for simpler command execution
Self {
executable: "cmd.exe".to_string(),
arg: "/C".to_string(),
redirect_syntax: "2>&1".to_string(), // cmd.exe also supports this syntax
}
} else {
Self {
Expand All @@ -45,13 +32,8 @@ pub fn get_shell_config() -> ShellConfig {

pub fn format_command_for_platform(command: &str) -> String {
let config = get_shell_config();
if cfg!(windows) && config.executable == "powershell.exe" {
// For Windows PowerShell, wrap the command in braces
format!("{{ {} }} {}", command, config.redirect_syntax)
} else {
// For cmd.exe and Unix shells, no braces needed
format!("{} {}", command, config.redirect_syntax)
}
// For all shells, no braces needed
format!("{} {}", command, config.redirect_syntax)
}

pub fn expand_path(path_str: &str) -> String {
Expand Down Expand Up @@ -87,4 +69,4 @@ pub fn normalize_line_endings(text: &str) -> String {
// Ensure LF line endings on Unix
text.replace("\r\n", "\n")
}
}
}

0 comments on commit 99dfb87

Please sign in to comment.