From 6cd4319fcf540ef70f74cc2f10d0d4297ee7b788 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Thu, 11 Apr 2024 16:59:01 +0100 Subject: feat(gui): add base structure (#1935) * initial * ui things * cargo * update, add history refresh button * history page a bit better, add initial dotfiles page * re-org layout * bye squigglies * add dotfiles ui, show aliases * add default shell detection * put stats in a little drawer, alias import changes * use new table for aliases, add alias deleting * support adding aliases * close drawer when added, no alias autocomplete * clippy, format * attempt to ensure gdk is installed ok * sudo * no linux things on mac ffs * I forgot we build for windows too... end of day * remove tauri backend from workspace --- atuin-dotfiles/src/shell.rs | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'atuin-dotfiles/src') diff --git a/atuin-dotfiles/src/shell.rs b/atuin-dotfiles/src/shell.rs index c779cadb..7912bc34 100644 --- a/atuin-dotfiles/src/shell.rs +++ b/atuin-dotfiles/src/shell.rs @@ -1,7 +1,7 @@ -use std::{ffi::OsStr, process::Command}; - -use atuin_common::shell::{shell, shell_name, ShellError}; use eyre::Result; +use serde::Serialize; + +use atuin_common::shell::{Shell, ShellError}; use crate::store::AliasStore; @@ -10,28 +10,12 @@ pub mod fish; pub mod xonsh; pub mod zsh; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct Alias { pub name: String, pub value: String, } -pub fn run_interactive(args: I) -> Result -where - I: IntoIterator, - S: AsRef, -{ - let shell = shell_name(None); - - let output = Command::new(shell) - .arg("-ic") - .args(args) - .output() - .map_err(|e| ShellError::ExecError(e.to_string()))?; - - Ok(String::from_utf8(output.stdout).unwrap()) -} - pub fn parse_alias(line: &str) -> Alias { let mut parts = line.split('='); @@ -44,15 +28,21 @@ pub fn parse_alias(line: &str) -> Alias { } } -pub fn existing_aliases() -> Result, ShellError> { +pub fn existing_aliases(shell: Option) -> Result, ShellError> { + let shell = if let Some(shell) = shell { + shell + } else { + Shell::current() + }; + // this only supports posix-y shells atm - if !shell().is_posixish() { + if !shell.is_posixish() { return Err(ShellError::NotSupported); } // This will return a list of aliases, each on its own line // They will be in the form foo=bar - let aliases = run_interactive(["alias"])?; + let aliases = shell.run_interactive(["alias"])?; let aliases: Vec = aliases.lines().map(parse_alias).collect(); Ok(aliases) @@ -62,7 +52,7 @@ pub fn existing_aliases() -> Result, ShellError> { /// This will not import aliases already in the store /// Returns aliases that were set pub async fn import_aliases(store: AliasStore) -> Result> { - let shell_aliases = existing_aliases()?; + let shell_aliases = existing_aliases(None)?; let store_aliases = store.aliases().await?; let mut res = Vec::new(); -- cgit v1.3.1