diff options
| author | YummyOreo <bobgim20@gmail.com> | 2024-06-19 05:55:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-19 11:55:03 +0100 |
| commit | 5f66fb6a0365994ae2d0702e19c85c649acdd1a7 (patch) | |
| tree | bd3574385e476190a1ca0e5aa6b67dd1e54ee83a /crates/atuin-common/src | |
| parent | Fix `scroll_exits` default in `config.toml` (#2166) (diff) | |
| download | atuin-5f66fb6a0365994ae2d0702e19c85c649acdd1a7.zip | |
fix(gui): add support for checking if the cli is installed on windows (#2162)
* fix(windows): add support for checking if the cli is installed on windows
* refactor: remove debugging info
* refactor: cargo fmt
Diffstat (limited to 'crates/atuin-common/src')
| -rw-r--r-- | crates/atuin-common/src/shell.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/crates/atuin-common/src/shell.rs b/crates/atuin-common/src/shell.rs index 80cdc742..32da6a8d 100644 --- a/crates/atuin-common/src/shell.rs +++ b/crates/atuin-common/src/shell.rs @@ -4,6 +4,7 @@ use serde::Serialize; use sysinfo::{get_current_pid, Process, System}; use thiserror::Error; +#[derive(PartialEq)] pub enum Shell { Sh, Bash, @@ -11,6 +12,7 @@ pub enum Shell { Zsh, Xonsh, Nu, + Powershell, Unknown, } @@ -24,6 +26,7 @@ impl std::fmt::Display for Shell { Shell::Nu => "nu", Shell::Xonsh => "xonsh", Shell::Sh => "sh", + Shell::Powershell => "powershell", Shell::Unknown => "unknown", }; @@ -91,6 +94,8 @@ impl Shell { Shell::Sh.run_interactive([ "dscl localhost -read \"/Local/Default/Users/$USER\" shell | awk '{print $2}'", ])? + } else if cfg!(windows) { + return Ok(Shell::Powershell); } else { Shell::Sh.run_interactive(["getent passwd $LOGNAME | cut -d: -f7"])? }; @@ -115,6 +120,7 @@ impl Shell { "xonsh" => Shell::Xonsh, "nu" => Shell::Nu, "sh" => Shell::Sh, + "powershell" => Shell::Powershell, _ => Shell::Unknown, } @@ -133,12 +139,18 @@ impl Shell { S: AsRef<OsStr>, { let shell = self.to_string(); - - let output = Command::new(shell) - .arg("-ic") - .args(args) - .output() - .map_err(|e| ShellError::ExecError(e.to_string()))?; + let output = if self == &Self::Powershell { + Command::new(shell) + .args(args) + .output() + .map_err(|e| ShellError::ExecError(e.to_string()))? + } else { + Command::new(shell) + .arg("-ic") + .args(args) + .output() + .map_err(|e| ShellError::ExecError(e.to_string()))? + }; Ok(String::from_utf8(output.stdout).unwrap()) } |
