aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-dotfiles/src/store
diff options
context:
space:
mode:
authorLucas Trzesniewski <lucas.trzesniewski@gmail.com>2025-10-23 22:03:39 +0200
committerGitHub <noreply@github.com>2025-10-23 13:03:39 -0700
commit592df559da03d6b50260f9d75f194fa4ccf1ea67 (patch)
tree27e557a85edc3be1249e338f44b0527d30a51694 /crates/atuin-dotfiles/src/store
parentchore: update changelog (diff)
downloadatuin-592df559da03d6b50260f9d75f194fa4ccf1ea67.zip
feat Add PowerShell support (#2543)
This adds PowerShell support 🎉 I built this script around @lzybkr's [prototype](https://github.com/atuinsh/atuin/issues/84#issuecomment-1689168533), so I added him as co-author (I hope that's ok). I wouldn't know where to start without his contribution. I'm not a PowerShell expert, so this was a nice opportunity to learn some stuff. I think it's ok, but I would appreciate if someone more knowledgeable in the matter could review this though. It would be nice if other PowerShell users could test this with their configs and report any issues. I wouldn't be surprised if there are some remaining bugs or missing features. Fixes #84 ## Installation If you'd like to test this, you can install the `atuin` from this PR by running: ```powershell cargo install --git https://github.com/ltrzesniewski/atuin.git --branch powershell-pr ``` Then, add the following to your PowerShell profile file (whose path is in `$PROFILE`) and restart the shell: ```powershell atuin init powershell | Out-String | Invoke-Expression ``` This requires `atuin` to be in the path and the [PSReadLine](https://github.com/PowerShell/PSReadLine) module to be installed, which is the case by default. ## Tests I tested this on the following: - PowerShell 7.4.6 / PSReadLine 2.3.5 / Windows (the latest one) - PowerShell 7.5.1 / PSReadLine 2.3.6 / Windows (the latest one) - PowerShell 5.1.22621.4391 / PSReadLine 2.0.0 / Windows (the one shipped with Windows) - PowerShell 7.4.6 / PSReadLine 2.3.5 / Ubuntu WSL (strangely, it didn't behave exactly like the Windows version) - PowerShell 7.5.1 / PSReadLine 2.3.6 / Ubuntu WSL I also tested this with and without my custom [Oh My Posh](https://ohmyposh.dev/) prompt. It works fine in both cases, ~except that since my OMP config contains `"newline": true`, my prompt is multiline and shifts downwards by a single line on each `atuin search -i` invocation. This can be adjusted with the `$env:ATUIN_POWERSHELL_PROMPT_OFFSET` environment variable (e.g. I set mine to `-1` to account for the additional prompt line).~ (this variable is now auto-initialized). ## Checks - [x] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [x] I have checked that there are no existing pull requests for the same thing --------- Co-authored-by: Jason Shirk <jasonsh@microsoft.com>
Diffstat (limited to 'crates/atuin-dotfiles/src/store')
-rw-r--r--crates/atuin-dotfiles/src/store/var.rs53
1 files changed, 41 insertions, 12 deletions
diff --git a/crates/atuin-dotfiles/src/store/var.rs b/crates/atuin-dotfiles/src/store/var.rs
index 402ba684..9d25b85d 100644
--- a/crates/atuin-dotfiles/src/store/var.rs
+++ b/crates/atuin-dotfiles/src/store/var.rs
@@ -169,7 +169,25 @@ impl VarStore {
pub async fn xonsh(&self) -> Result<String> {
let env = self.vars().await?;
+ Ok(Self::format_xonsh(&env))
+ }
+ pub async fn fish(&self) -> Result<String> {
+ let env = self.vars().await?;
+ Ok(Self::format_fish(&env))
+ }
+
+ pub async fn posix(&self) -> Result<String> {
+ let env = self.vars().await?;
+ Ok(Self::format_posix(&env))
+ }
+
+ pub async fn powershell(&self) -> Result<String> {
+ let env = self.vars().await?;
+ Ok(Self::format_powershell(&env))
+ }
+
+ fn format_xonsh(env: &[Var]) -> String {
let mut config = String::new();
for env in env {
@@ -177,12 +195,10 @@ impl VarStore {
config.push_str(&format!("${}={}\n", env.name, escaped_value));
}
- Ok(config)
+ config
}
- pub async fn fish(&self) -> Result<String> {
- let env = self.vars().await?;
-
+ fn format_fish(env: &[Var]) -> String {
let mut config = String::new();
for env in env {
@@ -190,12 +206,10 @@ impl VarStore {
config.push_str(&format!("set -gx {} {}\n", env.name, escaped_value));
}
- Ok(config)
+ config
}
- pub async fn posix(&self) -> Result<String> {
- let env = self.vars().await?;
-
+ fn format_posix(env: &[Var]) -> String {
let mut config = String::new();
for env in env {
@@ -207,17 +221,30 @@ impl VarStore {
}
}
- Ok(config)
+ config
+ }
+
+ fn format_powershell(env: &[Var]) -> String {
+ let mut config = String::new();
+
+ for var in env {
+ config.push_str(&crate::shell::powershell::format_var(var));
+ }
+
+ config
}
pub async fn build(&self) -> Result<()> {
let dir = atuin_common::utils::dotfiles_cache_dir();
tokio::fs::create_dir_all(dir.clone()).await?;
+ let env = self.vars().await?;
+
// Build for all supported shells
- let posix = self.posix().await?;
- let xonsh = self.xonsh().await?;
- let fsh = self.fish().await?;
+ let posix = Self::format_posix(&env);
+ let xonsh = Self::format_xonsh(&env);
+ let fsh = Self::format_fish(&env);
+ let powershell = Self::format_powershell(&env);
// All the same contents, maybe optimize in the future or perhaps there will be quirks
// per-shell
@@ -226,11 +253,13 @@ impl VarStore {
let bash = dir.join("vars.bash");
let fish = dir.join("vars.fish");
let xsh = dir.join("vars.xsh");
+ let ps1 = dir.join("vars.ps1");
tokio::fs::write(zsh, &posix).await?;
tokio::fs::write(bash, &posix).await?;
tokio::fs::write(fish, &fsh).await?;
tokio::fs::write(xsh, &xonsh).await?;
+ tokio::fs::write(ps1, &powershell).await?;
Ok(())
}