diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-04-11 16:59:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-11 16:59:01 +0100 |
| commit | 6cd4319fcf540ef70f74cc2f10d0d4297ee7b788 (patch) | |
| tree | 3d24dbf70493c377e162d9941faac65c829623f9 /atuin-dotfiles/src | |
| parent | feat(bash/blesh): use _ble_exec_time_ata for duration even in bash < 5 (#1940) (diff) | |
| download | atuin-6cd4319fcf540ef70f74cc2f10d0d4297ee7b788.zip | |
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
Diffstat (limited to 'atuin-dotfiles/src')
| -rw-r--r-- | atuin-dotfiles/src/shell.rs | 38 |
1 files changed, 14 insertions, 24 deletions
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<I, S>(args: I) -> Result<String, ShellError> -where - I: IntoIterator<Item = S>, - S: AsRef<OsStr>, -{ - 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<Vec<Alias>, ShellError> { +pub fn existing_aliases(shell: Option<Shell>) -> Result<Vec<Alias>, 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<Alias> = aliases.lines().map(parse_alias).collect(); Ok(aliases) @@ -62,7 +52,7 @@ pub fn existing_aliases() -> Result<Vec<Alias>, ShellError> { /// This will not import aliases already in the store /// Returns aliases that were set pub async fn import_aliases(store: AliasStore) -> Result<Vec<Alias>> { - let shell_aliases = existing_aliases()?; + let shell_aliases = existing_aliases(None)?; let store_aliases = store.aliases().await?; let mut res = Vec::new(); |
