mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-28 19:23:47 +01:00
feat: add env syncing support for nushell
This commit is contained in:
parent
36ddd98b6e
commit
e4bd0e4894
@ -10,6 +10,7 @@ pub mod bash;
|
||||
pub mod fish;
|
||||
pub mod xonsh;
|
||||
pub mod zsh;
|
||||
pub mod nu;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
pub struct Alias {
|
||||
|
7
crates/atuin-dotfiles/src/shell/nu.rs
Normal file
7
crates/atuin-dotfiles/src/shell/nu.rs
Normal file
@ -0,0 +1,7 @@
|
||||
pub async fn var_config() -> String {
|
||||
// Because nushell won't autoupdate, we just parse the output of `atuin dotfiles var list` in
|
||||
// nushell and load the env vars that way
|
||||
|
||||
// we should only do this if the dotfiles are enabled
|
||||
String::from(r#"atuin dotfiles var list | lines | parse "export {name}={value}" | reduce -f {} {|it, acc| $acc | upsert $it.name $it.value} | load-env"#)
|
||||
}
|
@ -7,6 +7,7 @@ use eyre::{Result, WrapErr};
|
||||
|
||||
mod bash;
|
||||
mod fish;
|
||||
mod nu;
|
||||
mod xonsh;
|
||||
mod zsh;
|
||||
|
||||
@ -38,51 +39,6 @@ pub enum Shell {
|
||||
}
|
||||
|
||||
impl Cmd {
|
||||
fn init_nu(&self) {
|
||||
let full = include_str!("../../shell/atuin.nu");
|
||||
println!("{full}");
|
||||
|
||||
if std::env::var("ATUIN_NOBIND").is_err() {
|
||||
const BIND_CTRL_R: &str = r"$env.config = (
|
||||
$env.config | upsert keybindings (
|
||||
$env.config.keybindings
|
||||
| append {
|
||||
name: atuin
|
||||
modifier: control
|
||||
keycode: char_r
|
||||
mode: [emacs, vi_normal, vi_insert]
|
||||
event: { send: executehostcommand cmd: (_atuin_search_cmd) }
|
||||
}
|
||||
)
|
||||
)";
|
||||
const BIND_UP_ARROW: &str = r"
|
||||
$env.config = (
|
||||
$env.config | upsert keybindings (
|
||||
$env.config.keybindings
|
||||
| append {
|
||||
name: atuin
|
||||
modifier: none
|
||||
keycode: up
|
||||
mode: [emacs, vi_normal, vi_insert]
|
||||
event: {
|
||||
until: [
|
||||
{send: menuup}
|
||||
{send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
";
|
||||
if !self.disable_ctrl_r {
|
||||
println!("{BIND_CTRL_R}");
|
||||
}
|
||||
if !self.disable_up_arrow {
|
||||
println!("{BIND_UP_ARROW}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn static_init(&self) {
|
||||
match self.shell {
|
||||
Shell::Zsh => {
|
||||
@ -95,7 +51,7 @@ $env.config = (
|
||||
fish::init_static(self.disable_up_arrow, self.disable_ctrl_r);
|
||||
}
|
||||
Shell::Nu => {
|
||||
self.init_nu();
|
||||
nu::init_static(self.disable_up_arrow, self.disable_ctrl_r);
|
||||
}
|
||||
Shell::Xonsh => {
|
||||
xonsh::init_static(self.disable_up_arrow, self.disable_ctrl_r);
|
||||
@ -143,7 +99,9 @@ $env.config = (
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Shell::Nu => self.init_nu(),
|
||||
Shell::Nu => {
|
||||
nu::init(self.disable_up_arrow, self.disable_ctrl_r).await?;
|
||||
}
|
||||
Shell::Xonsh => {
|
||||
xonsh::init(
|
||||
alias_store,
|
||||
|
55
crates/atuin/src/command/client/init/nu.rs
Normal file
55
crates/atuin/src/command/client/init/nu.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use eyre::Result;
|
||||
|
||||
const BIND_CTRL_R: &str = r"$env.config = (
|
||||
$env.config | upsert keybindings (
|
||||
$env.config.keybindings
|
||||
| append {
|
||||
name: atuin
|
||||
modifier: control
|
||||
keycode: char_r
|
||||
mode: [emacs, vi_normal, vi_insert]
|
||||
event: { send: executehostcommand cmd: (_atuin_search_cmd) }
|
||||
}
|
||||
)
|
||||
)";
|
||||
const BIND_UP_ARROW: &str = r"
|
||||
$env.config = (
|
||||
$env.config | upsert keybindings (
|
||||
$env.config.keybindings
|
||||
| append {
|
||||
name: atuin
|
||||
modifier: none
|
||||
keycode: up
|
||||
mode: [emacs, vi_normal, vi_insert]
|
||||
event: {
|
||||
until: [
|
||||
{send: menuup}
|
||||
{send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
";
|
||||
|
||||
pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool) {
|
||||
let full = include_str!("../../../shell/atuin.nu");
|
||||
println!("{full}");
|
||||
|
||||
if !disable_ctrl_r && std::env::var("ATUIN_NOBIND").is_err() {
|
||||
println!("{BIND_CTRL_R}");
|
||||
}
|
||||
if !disable_up_arrow && std::env::var("ATUIN_NOBIND").is_err() {
|
||||
println!("{BIND_UP_ARROW}");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn init(disable_up_arrow: bool, disable_ctrl_r: bool) -> Result<()> {
|
||||
init_static(disable_up_arrow, disable_ctrl_r);
|
||||
|
||||
let vars = atuin_dotfiles::shell::nu::var_config().await;
|
||||
|
||||
println!("{vars}");
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user