mirror of
https://github.com/atuinsh/atuin.git
synced 2026-07-16 16:47:14 +02:00
fix(init): fix include guard in Bash init script; chore(init): improve inclusion of shell init scripts in Rust (#3645)
Codespell / Check for spelling errors (push) Waiting to run
build-docker / publish (push) Waiting to run
Install / install (depot-ubuntu-24.04) (push) Waiting to run
Install / install (macos-14) (push) Waiting to run
Nix / check (push) Waiting to run
Nix / build-test (push) Waiting to run
Rust / build (depot-ubuntu-24.04) (push) Waiting to run
Rust / build (macos-14) (push) Waiting to run
Rust / build (windows-latest) (push) Waiting to run
Rust / cross-compile (x86_64-unknown-illumos) (push) Waiting to run
Rust / unit-test (depot-ubuntu-24.04) (push) Waiting to run
Rust / unit-test (macos-14) (push) Waiting to run
Rust / unit-test (windows-latest) (push) Waiting to run
Rust / check (depot-ubuntu-24.04) (push) Waiting to run
Rust / check (macos-14) (push) Waiting to run
Rust / check (windows-latest) (push) Waiting to run
Rust / integration-test (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust / format (push) Waiting to run
Shellcheck / shellcheck (push) Waiting to run
Codespell / Check for spelling errors (push) Waiting to run
build-docker / publish (push) Waiting to run
Install / install (depot-ubuntu-24.04) (push) Waiting to run
Install / install (macos-14) (push) Waiting to run
Nix / check (push) Waiting to run
Nix / build-test (push) Waiting to run
Rust / build (depot-ubuntu-24.04) (push) Waiting to run
Rust / build (macos-14) (push) Waiting to run
Rust / build (windows-latest) (push) Waiting to run
Rust / cross-compile (x86_64-unknown-illumos) (push) Waiting to run
Rust / unit-test (depot-ubuntu-24.04) (push) Waiting to run
Rust / unit-test (macos-14) (push) Waiting to run
Rust / unit-test (windows-latest) (push) Waiting to run
Rust / check (depot-ubuntu-24.04) (push) Waiting to run
Rust / check (macos-14) (push) Waiting to run
Rust / check (windows-latest) (push) Waiting to run
Rust / integration-test (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust / format (push) Waiting to run
Shellcheck / shellcheck (push) Waiting to run
* Ensure the entire Bash init script is covered by the include guard. `client/init/bash.rs` outputs code dynamically but it wasn't covered by the include guard. * Add `atuin::shell` module with all init scripts instead of calling `include_str!` from files in `command/client/init` * Strip trailing whitespace from the shell init scripts; they are all printed using `println!` which will add a newline
This commit is contained in:
@@ -52,10 +52,8 @@ pub enum Shell {
|
||||
|
||||
impl Cmd {
|
||||
fn init_nu(&self, _tmux: &Tmux) {
|
||||
let full = include_str!("../../shell/atuin.nu");
|
||||
|
||||
// TODO: tmux popup for Nu
|
||||
println!("{full}");
|
||||
println!("{}", crate::shell::NU);
|
||||
|
||||
if std::env::var("ATUIN_NOBIND").is_err() {
|
||||
const BIND_CTRL_R: &str = r"$env.config = (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::shell::BASH;
|
||||
use atuin_client::settings::Tmux;
|
||||
use atuin_dotfiles::store::{AliasStore, var::VarStore};
|
||||
use eyre::Result;
|
||||
@@ -12,24 +13,24 @@ fn print_tmux_config(tmux: &Tmux) {
|
||||
}
|
||||
|
||||
pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, disable_ai: bool, tmux: &Tmux) {
|
||||
let base = include_str!("../../../shell/atuin.bash");
|
||||
|
||||
let (bind_ctrl_r, bind_up_arrow) = if std::env::var("ATUIN_NOBIND").is_ok() {
|
||||
(false, false)
|
||||
} else {
|
||||
(!disable_ctrl_r, !disable_up_arrow)
|
||||
};
|
||||
|
||||
println!("{} && {{", BASH.include_guard);
|
||||
print_tmux_config(tmux);
|
||||
println!("__atuin_bind_ctrl_r={bind_ctrl_r}");
|
||||
println!("__atuin_bind_up_arrow={bind_up_arrow}");
|
||||
println!("{base}");
|
||||
println!("{}", BASH.main);
|
||||
|
||||
#[cfg(feature = "ai")]
|
||||
if !disable_ai {
|
||||
let bind_ai = atuin_ai::commands::init::generate_bash_integration();
|
||||
println!("{bind_ai}");
|
||||
}
|
||||
println!("}}");
|
||||
}
|
||||
|
||||
pub async fn init(
|
||||
|
||||
@@ -40,10 +40,8 @@ fn print_bindings(
|
||||
pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, disable_ai: bool, tmux: &Tmux) {
|
||||
let indent = " ".repeat(4);
|
||||
|
||||
let base = include_str!("../../../shell/atuin.fish");
|
||||
|
||||
print_tmux_config(tmux);
|
||||
println!("{base}");
|
||||
println!("{}", crate::shell::FISH);
|
||||
|
||||
if std::env::var("ATUIN_NOBIND").is_err() {
|
||||
println!("if string match -q '4.*' $version");
|
||||
|
||||
@@ -2,8 +2,6 @@ use atuin_client::settings::Tmux;
|
||||
use atuin_dotfiles::store::{AliasStore, var::VarStore};
|
||||
|
||||
pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, _tmux: &Tmux) {
|
||||
let base = include_str!("../../../shell/atuin.ps1");
|
||||
|
||||
let (bind_ctrl_r, bind_up_arrow) = if std::env::var("ATUIN_NOBIND").is_ok() {
|
||||
(false, false)
|
||||
} else {
|
||||
@@ -11,7 +9,7 @@ pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, _tmux: &Tmux) {
|
||||
};
|
||||
|
||||
// TODO: tmux popup for Powershell
|
||||
println!("{base}");
|
||||
println!("{}", crate::shell::POWERSHELL);
|
||||
println!(
|
||||
"Enable-AtuinSearchKeys -CtrlR {} -UpArrow {}",
|
||||
ps_bool(bind_ctrl_r),
|
||||
|
||||
@@ -3,8 +3,6 @@ use atuin_dotfiles::store::{AliasStore, var::VarStore};
|
||||
use eyre::Result;
|
||||
|
||||
pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, _tmux: &Tmux) {
|
||||
let base = include_str!("../../../shell/atuin.xsh");
|
||||
|
||||
let (bind_ctrl_r, bind_up_arrow) = if std::env::var("ATUIN_NOBIND").is_ok() {
|
||||
(false, false)
|
||||
} else {
|
||||
@@ -20,7 +18,7 @@ pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, _tmux: &Tmux) {
|
||||
"_ATUIN_BIND_UP_ARROW={}",
|
||||
if bind_up_arrow { "True" } else { "False" }
|
||||
);
|
||||
println!("{base}");
|
||||
println!("{}", crate::shell::XONSH);
|
||||
}
|
||||
|
||||
pub async fn init(
|
||||
|
||||
@@ -12,10 +12,8 @@ fn print_tmux_config(tmux: &Tmux) {
|
||||
}
|
||||
|
||||
pub fn init_static(disable_up_arrow: bool, disable_ctrl_r: bool, disable_ai: bool, tmux: &Tmux) {
|
||||
let base = include_str!("../../../shell/atuin.zsh");
|
||||
|
||||
print_tmux_config(tmux);
|
||||
println!("{base}");
|
||||
println!("{}", crate::shell::ZSH);
|
||||
|
||||
if std::env::var("ATUIN_NOBIND").is_err() {
|
||||
const BIND_CTRL_R: &str = r"bindkey -M emacs '^r' atuin-search
|
||||
|
||||
@@ -10,6 +10,8 @@ use command::AtuinCmd;
|
||||
|
||||
mod command;
|
||||
pub(crate) mod logs;
|
||||
#[cfg(feature = "client")]
|
||||
pub(crate) mod shell;
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
mod print_error;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
macro_rules! include_shell {
|
||||
($path:literal) => {
|
||||
include_str!(concat!("shell/", $path)).trim_ascii_end()
|
||||
};
|
||||
}
|
||||
|
||||
pub struct Bash<'a> {
|
||||
pub include_guard: &'a str,
|
||||
pub main: &'a str,
|
||||
}
|
||||
|
||||
pub const BASH: Bash<'_> = Bash {
|
||||
include_guard: include_shell!("atuin.bash.d/include-guard.bash"),
|
||||
main: include_shell!("atuin.bash"),
|
||||
};
|
||||
|
||||
pub const FISH: &str = include_shell!("atuin.fish");
|
||||
pub const NU: &str = include_shell!("atuin.nu");
|
||||
pub const POWERSHELL: &str = include_shell!("atuin.ps1");
|
||||
pub const XONSH: &str = include_shell!("atuin.xsh");
|
||||
pub const ZSH: &str = include_shell!("atuin.zsh");
|
||||
@@ -1,15 +1,3 @@
|
||||
# Include guard
|
||||
if [[ ${__atuin_initialized-} == true ]]; then
|
||||
false
|
||||
elif [[ $- != *i* ]]; then
|
||||
# Enable only in interactive shells
|
||||
false
|
||||
elif ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 1)); then
|
||||
# Require bash >= 3.1
|
||||
[[ -t 2 ]] && printf 'atuin: requires bash >= 3.1 for the integration.\n' >&2
|
||||
false
|
||||
else # (include guard) beginning of main content
|
||||
#------------------------------------------------------------------------------
|
||||
__atuin_initialized=true
|
||||
|
||||
if [[ -z "${ATUIN_SESSION:-}" || "${ATUIN_SHLVL:-}" != "$SHLVL" ]]; then
|
||||
@@ -720,6 +708,3 @@ if [[ $__atuin_bind_up_arrow == true ]]; then
|
||||
atuin-bind -m vi-command '\eOA' atuin-up-search-vicmd
|
||||
atuin-bind -m vi-command 'k' atuin-up-search-vicmd
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
fi # (include guard) end of main content
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# Include guard
|
||||
if [[ ${__atuin_initialized-} == true ]]; then
|
||||
false
|
||||
elif [[ $- != *i* ]]; then
|
||||
# Enable only in interactive shells
|
||||
false
|
||||
elif ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 1)); then
|
||||
# Require bash >= 3.1
|
||||
[[ -t 2 ]] && printf 'atuin: requires bash >= 3.1 for the integration.\n' >&2
|
||||
false
|
||||
else
|
||||
true
|
||||
fi
|
||||
Reference in New Issue
Block a user