summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYummyOreo <bobgim20@gmail.com>2024-06-19 05:55:03 -0500
committerGitHub <noreply@github.com>2024-06-19 11:55:03 +0100
commit5f66fb6a0365994ae2d0702e19c85c649acdd1a7 (patch)
treebd3574385e476190a1ca0e5aa6b67dd1e54ee83a
parent33ef734116dfa4d58f96095974cb687122c0d61a (diff)
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
-rw-r--r--crates/atuin-common/src/shell.rs24
-rw-r--r--ui/backend/src/install.rs11
2 files changed, 26 insertions, 9 deletions
diff --git a/crates/atuin-common/src/shell.rs b/crates/atuin-common/src/shell.rs
index 80cdc7423..32da6a8d0 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())
}
diff --git a/ui/backend/src/install.rs b/ui/backend/src/install.rs
index 55877c4b2..43ad0c540 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<bool, String> {
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"))
}