Skip to content

Commit

Permalink
put stats in a little drawer, alias import changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ellie committed Apr 10, 2024
1 parent 902b7f2 commit 390ef0c
Show file tree
Hide file tree
Showing 17 changed files with 910 additions and 132 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions atuin-dotfiles/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ pub fn parse_alias(line: &str) -> Alias {
}
}

pub fn existing_aliases() -> Result<Vec<Alias>, ShellError> {
let shell = Shell::current();
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() {
Expand All @@ -48,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();
Expand Down
2 changes: 0 additions & 2 deletions atuin/src/command/client/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use sysinfo::{get_current_pid, Disks, System};
struct ShellInfo {
pub name: String,

// best-effort, not supported on all OSes

// best-effort, not supported on all OSes
pub default: String,

Expand Down
7 changes: 5 additions & 2 deletions ui/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ tauri-build = { version = "2.0.0-beta", features = [] }

[dependencies]
atuin-client = { path = "../../atuin-client", version = "18.1.0" }
atuin-common = { path = "../../atuin-common", version = "18.1.0" }

atuin-dotfiles = { path = "../../atuin-dotfiles", version = "0.1.0" }

sqlx = { workspace = true, features = ["sqlite", "regexp"] }
eyre = { workspace = true }

tauri = { version = "2.0.0-beta", features = ["tray-icon"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sqlx = { workspace = true, features = ["sqlite", "regexp"] }
time = "0.3.34"
uuid = "1.7.0"
syntect = "5.2.0"
async-trait = { workspace = true }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
60 changes: 49 additions & 11 deletions ui/backend/src/dotfiles/aliases.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
use std::path::PathBuf;

use atuin_client::{encryption, record::sqlite_store::SqliteStore, settings::Settings};
use atuin_dotfiles::{shell::Alias, store::AliasStore};
use atuin_common::shell::Shell;
use atuin_dotfiles::{
shell::{existing_aliases, Alias},
store::AliasStore,
};

#[tauri::command]
pub async fn aliases() -> Result<Vec<Alias>, String> {
let settings = Settings::new().map_err(|e| e.to_string())?;
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
.map_err(|e| e.to_string())?;
let sqlite_store = SqliteStore::new(record_store_path, settings.local_timeout).await?;

let encryption_key: [u8; 32] = encryption::load_key(&settings)
.map_err(|e| format!("could not load encryption key: {}", e.to_string()))?
.into();
let encryption_key: [u8; 32] = encryption::load_key(&settings)?.into();

let host_id = Settings::host_id().expect("failed to get host_id");

let alias_store = AliasStore::new(sqlite_store, host_id, encryption_key);
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()
Expand All @@ -27,3 +31,37 @@ pub async fn aliases() -> Result<Vec<Alias>, String> {

Ok(aliases)
}

#[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)
}
3 changes: 2 additions & 1 deletion ui/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ fn main() {
list,
search,
global_stats,
aliases
aliases,
dotfiles::aliases::import_aliases,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
17 changes: 17 additions & 0 deletions ui/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/styles.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
9 changes: 8 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
"@heroicons/react": "^2.1.3",
"@tailwindcss/forms": "^0.5.7",
"@tauri-apps/api": "2.0.0-beta.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"core": "link:@tauri-apps/api/core",
"highlight.js": "^11.9.0",
"lucide-react": "^0.367.0",
"luxon": "^3.4.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"recharts": "^2.12.4"
"react-spinners": "^0.13.8",
"recharts": "^2.12.4",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.0"
},
"devDependencies": {
"@tauri-apps/cli": "2.0.0-beta.2",
Expand Down
Loading

0 comments on commit 390ef0c

Please sign in to comment.