aboutsummaryrefslogtreecommitdiffstats
path: root/ui/backend/src/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 /ui/backend/src/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 'ui/backend/src/dotfiles')
-rw-r--r--ui/backend/src/dotfiles/aliases.rs91
-rw-r--r--ui/backend/src/dotfiles/mod.rs1
2 files changed, 92 insertions, 0 deletions
diff --git a/ui/backend/src/dotfiles/aliases.rs b/ui/backend/src/dotfiles/aliases.rs
new file mode 100644
index 00000000..972466fe
--- /dev/null
+++ b/ui/backend/src/dotfiles/aliases.rs
@@ -0,0 +1,91 @@
+use std::path::PathBuf;
+
+use atuin_client::{encryption, record::sqlite_store::SqliteStore, settings::Settings};
+use atuin_common::shell::Shell;
+use atuin_dotfiles::{
+ shell::{existing_aliases, Alias},
+ store::AliasStore,
+};
+
+async fn alias_store() -> eyre::Result<AliasStore> {
+ let settings = Settings::new()?;
+
+ let record_store_path = PathBuf::from(settings.record_store_path.as_str());
+ let sqlite_store = SqliteStore::new(record_store_path, settings.local_timeout).await?;
+
+ let encryption_key: [u8; 32] = encryption::load_key(&settings)?.into();
+
+ let host_id = Settings::host_id().expect("failed to get host_id");
+
+ Ok(AliasStore::new(sqlite_store, host_id, encryption_key))
+}
+
+#[tauri::command]
+pub async fn aliases() -> Result<Vec<Alias>, String> {
+ let alias_store = alias_store().await.map_err(|e| e.to_string())?;
+
+ let aliases = alias_store
+ .aliases()
+ .await
+ .map_err(|e| format!("failed to load aliases: {}", e))?;
+
+ Ok(aliases)
+}
+
+#[tauri::command]
+pub async fn delete_alias(name: String) -> Result<(), String> {
+ let alias_store = alias_store().await.map_err(|e| e.to_string())?;
+
+ alias_store
+ .delete(name.as_str())
+ .await
+ .map_err(|e| e.to_string())?;
+
+ Ok(())
+}
+
+#[tauri::command]
+pub async fn set_alias(name: String, value: String) -> Result<(), String> {
+ let alias_store = alias_store().await.map_err(|e| e.to_string())?;
+
+ alias_store
+ .set(name.as_str(), value.as_str())
+ .await
+ .map_err(|e| e.to_string())?;
+
+ Ok(())
+}
+
+#[tauri::command]
+pub async fn import_aliases() -> Result<Vec<Alias>, String> {
+ let store = alias_store().await.map_err(|e| e.to_string())?;
+ let shell = Shell::default_shell().map_err(|e| e.to_string())?;
+ let shell_name = shell.to_string();
+
+ if !shell.is_posixish() {
+ return Err(format!(
+ "Default shell {shell_name} not supported for import"
+ ));
+ }
+
+ let existing_aliases = existing_aliases(Some(shell)).map_err(|e| e.to_string())?;
+ let store_aliases = store.aliases().await.map_err(|e| e.to_string())?;
+
+ let mut res = Vec::new();
+
+ for alias in existing_aliases {
+ // O(n), but n is small, and imports infrequent
+ // can always make a map
+ if store_aliases.contains(&alias) {
+ continue;
+ }
+
+ res.push(alias.clone());
+ store
+ .set(&alias.name, &alias.value)
+ .await
+ .map_err(|e| e.to_string())?;
+ }
+
+ Ok(res)
+}
diff --git a/ui/backend/src/dotfiles/mod.rs b/ui/backend/src/dotfiles/mod.rs
new file mode 100644
index 00000000..d293a01b
--- /dev/null
+++ b/ui/backend/src/dotfiles/mod.rs
@@ -0,0 +1 @@
+pub mod aliases;