aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-dotfiles
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-04-11 16:59:01 +0100
committerGitHub <noreply@github.com>2024-04-11 16:59:01 +0100
commit6cd4319fcf540ef70f74cc2f10d0d4297ee7b788 (patch)
tree3d24dbf70493c377e162d9941faac65c829623f9 /atuin-dotfiles
parentfeat(bash/blesh): use _ble_exec_time_ata for duration even in bash < 5 (#1940) (diff)
downloadatuin-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')
-rw-r--r--atuin-dotfiles/Cargo.toml3
-rw-r--r--atuin-dotfiles/src/shell.rs38
2 files changed, 16 insertions, 25 deletions
diff --git a/atuin-dotfiles/Cargo.toml b/atuin-dotfiles/Cargo.toml
index d2c6589a..d5f59e13 100644
--- a/atuin-dotfiles/Cargo.toml
+++ b/atuin-dotfiles/Cargo.toml
@@ -2,7 +2,7 @@
name = "atuin-dotfiles"
description = "The dotfiles crate for Atuin"
edition = "2021"
-version = "0.1.0" # intentionally not the same as the rest
+version = "0.1.0" # intentionally not the same as the rest
authors.workspace = true
rust-version.workspace = true
@@ -21,4 +21,5 @@ eyre = { workspace = true }
tokio = { workspace = true }
rmp = { version = "0.8.11" }
rand = { workspace = true }
+serde = { workspace = true }
crypto_secretbox = "0.1.1"
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();