diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-10 22:01:45 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-10 22:01:45 +0200 |
| commit | 5e31a81cd2207f053b8cd8ad84ebe2a2f691b29d (patch) | |
| tree | 5d76811ab0d693c01fa472d41aa2ceaf3bd0b415 /crates/atuin-dotfiles/src/shell | |
| parent | chore: Remove unneeded files (diff) | |
| download | atuin-5e31a81cd2207f053b8cd8ad84ebe2a2f691b29d.zip | |
chore: Remove some unused rust code
Diffstat (limited to 'crates/atuin-dotfiles/src/shell')
| -rw-r--r-- | crates/atuin-dotfiles/src/shell/bash.rs | 68 | ||||
| -rw-r--r-- | crates/atuin-dotfiles/src/shell/fish.rs | 69 | ||||
| -rw-r--r-- | crates/atuin-dotfiles/src/shell/powershell.rs | 169 | ||||
| -rw-r--r-- | crates/atuin-dotfiles/src/shell/xonsh.rs | 68 | ||||
| -rw-r--r-- | crates/atuin-dotfiles/src/shell/zsh.rs | 68 |
5 files changed, 0 insertions, 442 deletions
diff --git a/crates/atuin-dotfiles/src/shell/bash.rs b/crates/atuin-dotfiles/src/shell/bash.rs deleted file mode 100644 index 2b9b4c88..00000000 --- a/crates/atuin-dotfiles/src/shell/bash.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::path::PathBuf; - -use crate::store::{AliasStore, var::VarStore}; - -async fn cached_aliases(path: PathBuf, store: &AliasStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(aliases) => aliases, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new aliases on the fly - - store.posix().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate aliases: \n{r}\n{e}'",) - }) - } - } -} - -async fn cached_vars(path: PathBuf, store: &VarStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(vars) => vars, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new vars on the fly - - store.posix().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate vars: \n{r}\n{e}'",) - }) - } - } -} - -/// Return bash dotfile config -/// -/// Do not return an error. We should not prevent the shell from starting. -/// -/// In the worst case, Atuin should not function but the shell should start correctly. -/// -/// While currently this only returns aliases, it will be extended to also return other synced dotfiles -pub async fn alias_config(store: &AliasStore) -> String { - // First try to read the cached config - let aliases = atuin_common::utils::dotfiles_cache_dir().join("aliases.bash"); - - if aliases.exists() { - return cached_aliases(aliases, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate aliases: {e}'"); - } - - cached_aliases(aliases, store).await -} - -pub async fn var_config(store: &VarStore) -> String { - // First try to read the cached config - let vars = atuin_common::utils::dotfiles_cache_dir().join("vars.bash"); - - if vars.exists() { - return cached_vars(vars, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate vars: {e}'"); - } - - cached_vars(vars, store).await -} diff --git a/crates/atuin-dotfiles/src/shell/fish.rs b/crates/atuin-dotfiles/src/shell/fish.rs deleted file mode 100644 index 6d472f67..00000000 --- a/crates/atuin-dotfiles/src/shell/fish.rs +++ /dev/null @@ -1,69 +0,0 @@ -// Configuration for fish -use std::path::PathBuf; - -use crate::store::{AliasStore, var::VarStore}; - -async fn cached_aliases(path: PathBuf, store: &AliasStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(aliases) => aliases, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new aliases on the fly - - store.posix().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate aliases: \n{r}\n{e}'",) - }) - } - } -} - -async fn cached_vars(path: PathBuf, store: &VarStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(vars) => vars, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new vars on the fly - - store.posix().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate vars: \n{r}\n{e}'",) - }) - } - } -} - -/// Return fish dotfile config -/// -/// Do not return an error. We should not prevent the shell from starting. -/// -/// In the worst case, Atuin should not function but the shell should start correctly. -/// -/// While currently this only returns aliases, it will be extended to also return other synced dotfiles -pub async fn alias_config(store: &AliasStore) -> String { - // First try to read the cached config - let aliases = atuin_common::utils::dotfiles_cache_dir().join("aliases.fish"); - - if aliases.exists() { - return cached_aliases(aliases, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate aliases: {e}'"); - } - - cached_aliases(aliases, store).await -} - -pub async fn var_config(store: &VarStore) -> String { - // First try to read the cached config - let vars = atuin_common::utils::dotfiles_cache_dir().join("vars.fish"); - - if vars.exists() { - return cached_vars(vars, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate vars: {e}'"); - } - - cached_vars(vars, store).await -} diff --git a/crates/atuin-dotfiles/src/shell/powershell.rs b/crates/atuin-dotfiles/src/shell/powershell.rs deleted file mode 100644 index 1daee28b..00000000 --- a/crates/atuin-dotfiles/src/shell/powershell.rs +++ /dev/null @@ -1,169 +0,0 @@ -use crate::shell::{Alias, Var}; -use crate::store::{AliasStore, var::VarStore}; -use std::path::PathBuf; - -async fn cached_aliases(path: PathBuf, store: &AliasStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(aliases) => aliases, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new aliases on the fly - - store.powershell().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate aliases: \n{r}\n{e}'",) - }) - } - } -} - -async fn cached_vars(path: PathBuf, store: &VarStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(vars) => vars, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new vars on the fly - - store.powershell().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate vars: \n{r}\n{e}'",) - }) - } - } -} - -/// Return powershell dotfile config -/// -/// Do not return an error. We should not prevent the shell from starting. -/// -/// In the worst case, Atuin should not function but the shell should start correctly. -/// -/// While currently this only returns aliases, it will be extended to also return other synced dotfiles -pub async fn alias_config(store: &AliasStore) -> String { - // First try to read the cached config - let aliases = atuin_common::utils::dotfiles_cache_dir().join("aliases.ps1"); - - if aliases.exists() { - return cached_aliases(aliases, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate aliases: {e}'"); - } - - cached_aliases(aliases, store).await -} - -pub async fn var_config(store: &VarStore) -> String { - // First try to read the cached config - let vars = atuin_common::utils::dotfiles_cache_dir().join("vars.ps1"); - - if vars.exists() { - return cached_vars(vars, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate vars: {e}'"); - } - - cached_vars(vars, store).await -} - -pub fn format_alias(alias: &Alias) -> String { - // Set-Alias doesn't support adding implicit arguments, so use a function. - // See https://github.com/PowerShell/PowerShell/issues/12962 - - let mut result = secure_command(&format!( - "function {} {{\n {}{} @args\n}}", - alias.name, - if alias.value.starts_with(['"', '\'']) { - "& " - } else { - "" - }, - alias.value - )); - - // This makes the file layout prettier - result.insert(0, '\n'); - result -} - -pub fn format_var(var: &Var) -> String { - secure_command(&format!( - "${}{} = '{}'", - if var.export { "env:" } else { "" }, - var.name, - var.value.replace("'", "''") - )) -} - -/// Wraps the given command in an Invoke-Expression to ensure the outer script is not halted -/// if the inner command contains a syntax error. -fn secure_command(command: &str) -> String { - format!( - "Invoke-Expression -ErrorAction Continue -Command '{}'\n", - command.replace("'", "''") - ) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn aliases() { - assert_eq!( - format_alias(&Alias { - name: "gp".to_string(), - value: "git push".to_string(), - }), - "\n".to_string() - + &secure_command( - "function gp { - git push @args -}" - ) - ); - - assert_eq!( - format_alias(&Alias { - name: "spc".to_string(), - value: "\"path with spaces\" arg".to_string(), - }), - "\n".to_string() - + &secure_command( - "function spc { - & \"path with spaces\" arg @args -}" - ) - ); - } - - #[test] - fn vars() { - assert_eq!( - format_var(&Var { - name: "FOO".to_owned(), - value: "bar 'baz'".to_owned(), - export: true, - }), - secure_command("$env:FOO = 'bar ''baz'''") - ); - - assert_eq!( - format_var(&Var { - name: "TEST".to_owned(), - value: "1".to_owned(), - export: false, - }), - secure_command("$TEST = '1'") - ); - } - - #[test] - fn invoke_expression() { - assert_eq!( - secure_command("echo 'foo'"), - "Invoke-Expression -ErrorAction Continue -Command 'echo ''foo'''\n" - ) - } -} diff --git a/crates/atuin-dotfiles/src/shell/xonsh.rs b/crates/atuin-dotfiles/src/shell/xonsh.rs deleted file mode 100644 index 1e56fc1d..00000000 --- a/crates/atuin-dotfiles/src/shell/xonsh.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::path::PathBuf; - -use crate::store::{AliasStore, var::VarStore}; - -async fn cached_aliases(path: PathBuf, store: &AliasStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(aliases) => aliases, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new aliases on the fly - - store.xonsh().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate aliases: \n{r}\n{e}'",) - }) - } - } -} - -async fn cached_vars(path: PathBuf, store: &VarStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(vars) => vars, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new vars on the fly - - store.xonsh().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate vars: \n{r}\n{e}'",) - }) - } - } -} - -/// Return xonsh dotfile config -/// -/// Do not return an error. We should not prevent the shell from starting. -/// -/// In the worst case, Atuin should not function but the shell should start correctly. -/// -/// While currently this only returns aliases, it will be extended to also return other synced dotfiles -pub async fn alias_config(store: &AliasStore) -> String { - // First try to read the cached config - let aliases = atuin_common::utils::dotfiles_cache_dir().join("aliases.xsh"); - - if aliases.exists() { - return cached_aliases(aliases, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate aliases: {e}'"); - } - - cached_aliases(aliases, store).await -} - -pub async fn var_config(store: &VarStore) -> String { - // First try to read the cached config - let vars = atuin_common::utils::dotfiles_cache_dir().join("vars.xsh"); - - if vars.exists() { - return cached_vars(vars, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate vars: {e}'"); - } - - cached_vars(vars, store).await -} diff --git a/crates/atuin-dotfiles/src/shell/zsh.rs b/crates/atuin-dotfiles/src/shell/zsh.rs deleted file mode 100644 index 117e9403..00000000 --- a/crates/atuin-dotfiles/src/shell/zsh.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::path::PathBuf; - -use crate::store::{AliasStore, var::VarStore}; - -async fn cached_aliases(path: PathBuf, store: &AliasStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(aliases) => aliases, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new aliases on the fly - - store.posix().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate aliases: \n{r}\n{e}'",) - }) - } - } -} - -async fn cached_vars(path: PathBuf, store: &VarStore) -> String { - match tokio::fs::read_to_string(path).await { - Ok(aliases) => aliases, - Err(r) => { - // we failed to read the file for some reason, but the file does exist - // fallback to generating new vars on the fly - - store.posix().await.unwrap_or_else(|e| { - format!("echo 'Atuin: failed to read and generate aliases: \n{r}\n{e}'",) - }) - } - } -} - -/// Return zsh dotfile config -/// -/// Do not return an error. We should not prevent the shell from starting. -/// -/// In the worst case, Atuin should not function but the shell should start correctly. -/// -/// While currently this only returns aliases, it will be extended to also return other synced dotfiles -pub async fn alias_config(store: &AliasStore) -> String { - // First try to read the cached config - let aliases = atuin_common::utils::dotfiles_cache_dir().join("aliases.zsh"); - - if aliases.exists() { - return cached_aliases(aliases, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate aliases: {e}'"); - } - - cached_aliases(aliases, store).await -} - -pub async fn var_config(store: &VarStore) -> String { - // First try to read the cached config - let vars = atuin_common::utils::dotfiles_cache_dir().join("vars.zsh"); - - if vars.exists() { - return cached_vars(vars, store).await; - } - - if let Err(e) = store.build().await { - return format!("echo 'Atuin: failed to generate aliases: {e}'"); - } - - cached_vars(vars, store).await -} |
