mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-20 18:07:57 +02: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 sysinfo::{get_current_pid, Process, System};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub enum Shell {
|
pub enum Shell {
|
||||||
Sh,
|
Sh,
|
||||||
Bash,
|
Bash,
|
||||||
@ -11,6 +12,7 @@ pub enum Shell {
|
|||||||
Zsh,
|
Zsh,
|
||||||
Xonsh,
|
Xonsh,
|
||||||
Nu,
|
Nu,
|
||||||
|
Powershell,
|
||||||
|
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
@ -24,6 +26,7 @@ impl std::fmt::Display for Shell {
|
|||||||
Shell::Nu => "nu",
|
Shell::Nu => "nu",
|
||||||
Shell::Xonsh => "xonsh",
|
Shell::Xonsh => "xonsh",
|
||||||
Shell::Sh => "sh",
|
Shell::Sh => "sh",
|
||||||
|
Shell::Powershell => "powershell",
|
||||||
|
|
||||||
Shell::Unknown => "unknown",
|
Shell::Unknown => "unknown",
|
||||||
};
|
};
|
||||||
@ -91,6 +94,8 @@ impl Shell {
|
|||||||
Shell::Sh.run_interactive([
|
Shell::Sh.run_interactive([
|
||||||
"dscl localhost -read \"/Local/Default/Users/$USER\" shell | awk '{print $2}'",
|
"dscl localhost -read \"/Local/Default/Users/$USER\" shell | awk '{print $2}'",
|
||||||
])?
|
])?
|
||||||
|
} else if cfg!(windows) {
|
||||||
|
return Ok(Shell::Powershell);
|
||||||
} else {
|
} else {
|
||||||
Shell::Sh.run_interactive(["getent passwd $LOGNAME | cut -d: -f7"])?
|
Shell::Sh.run_interactive(["getent passwd $LOGNAME | cut -d: -f7"])?
|
||||||
};
|
};
|
||||||
@ -115,6 +120,7 @@ impl Shell {
|
|||||||
"xonsh" => Shell::Xonsh,
|
"xonsh" => Shell::Xonsh,
|
||||||
"nu" => Shell::Nu,
|
"nu" => Shell::Nu,
|
||||||
"sh" => Shell::Sh,
|
"sh" => Shell::Sh,
|
||||||
|
"powershell" => Shell::Powershell,
|
||||||
|
|
||||||
_ => Shell::Unknown,
|
_ => Shell::Unknown,
|
||||||
}
|
}
|
||||||
@ -133,12 +139,18 @@ impl Shell {
|
|||||||
S: AsRef<OsStr>,
|
S: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
let shell = self.to_string();
|
let shell = self.to_string();
|
||||||
|
let output = if self == &Self::Powershell {
|
||||||
let output = Command::new(shell)
|
Command::new(shell)
|
||||||
|
.args(args)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| ShellError::ExecError(e.to_string()))?
|
||||||
|
} else {
|
||||||
|
Command::new(shell)
|
||||||
.arg("-ic")
|
.arg("-ic")
|
||||||
.args(args)
|
.args(args)
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| ShellError::ExecError(e.to_string()))?;
|
.map_err(|e| ShellError::ExecError(e.to_string()))?
|
||||||
|
};
|
||||||
|
|
||||||
Ok(String::from_utf8(output.stdout).unwrap())
|
Ok(String::from_utf8(output.stdout).unwrap())
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,14 @@ pub(crate) async fn install_cli() -> Result<(), String> {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub(crate) async fn is_cli_installed() -> Result<bool, String> {
|
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 shell = Shell::default_shell().map_err(|e| format!("Failed to get default shell: {e}"))?;
|
||||||
let output = shell
|
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'"])
|
.run_interactive(&["atuin --version && echo 'ATUIN FOUND'"])
|
||||||
.map_err(|e| format!("Failed to run interactive command"))?;
|
.map_err(|e| format!("Failed to run interactive command"))?
|
||||||
|
};
|
||||||
|
|
||||||
Ok(output.contains("ATUIN FOUND"))
|
Ok(output.contains("ATUIN FOUND"))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user