mirror of
https://github.com/atuinsh/atuin.git
synced 2025-02-10 07:30:06 +01:00
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
This commit is contained in:
parent
33ef734116
commit
5f66fb6a03
@ -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())
|
||||
}
|
||||
|
@ -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"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user