From 5f66fb6a0365994ae2d0702e19c85c649acdd1a7 Mon Sep 17 00:00:00 2001 From: YummyOreo Date: Wed, 19 Jun 2024 05:55:03 -0500 Subject: 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 --- crates/atuin-common/src/shell.rs | 24 ++++++++++++++++++------ ui/backend/src/install.rs | 11 ++++++++--- 2 files changed, 26 insertions(+), 9 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, { 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()) } diff --git a/ui/backend/src/install.rs b/ui/backend/src/install.rs index 55877c4b..43ad0c54 100644 --- a/ui/backend/src/install.rs +++ b/ui/backend/src/install.rs @@ -23,9 +23,14 @@ pub(crate) async fn install_cli() -> Result<(), String> { #[tauri::command] pub(crate) async fn is_cli_installed() -> Result { let shell = Shell::default_shell().map_err(|e| format!("Failed to get default shell: {e}"))?; - let output = shell - .run_interactive(&["atuin --version && echo 'ATUIN FOUND'"]) - .map_err(|e| format!("Failed to run interactive command"))?; + let output = if shell == Shell::Powershell { + shell.run_interactive(&["atuin --version; if ($?) {echo 'ATUIN FOUND'}"]) + .map_err(|e| format!("Failed to run interactive command"))? + } else { + shell + .run_interactive(&["atuin --version && echo 'ATUIN FOUND'"]) + .map_err(|e| format!("Failed to run interactive command"))? + }; Ok(output.contains("ATUIN FOUND")) } -- cgit v1.3.1