aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crates/atuin-hex/src/lib.rs48
-rw-r--r--docs/docs/reference/hex.md65
-rw-r--r--docs/mkdocs.yml1
3 files changed, 77 insertions, 37 deletions
diff --git a/crates/atuin-hex/src/lib.rs b/crates/atuin-hex/src/lib.rs
index b08da631..feed6e36 100644
--- a/crates/atuin-hex/src/lib.rs
+++ b/crates/atuin-hex/src/lib.rs
@@ -29,17 +29,6 @@ enum Shell {
Nu,
}
-impl Shell {
- fn as_str(self) -> &'static str {
- match self {
- Self::Bash => "bash",
- Self::Zsh => "zsh",
- Self::Fish => "fish",
- Self::Nu => "nu",
- }
- }
-}
-
impl Init {
fn run(self) -> Result<(), String> {
let shell = detect_shell(self.shell)?;
@@ -102,15 +91,9 @@ fn shell_from_name(name: &str) -> Option<Shell> {
}
}
-fn init_command(shell: Shell) -> String {
- format!("atuin init {}", shell.as_str())
-}
-
-fn render_init(shell: Shell) -> String {
- let init_command = init_command(shell);
-
+fn render_init(shell: Shell) -> &'static str {
match shell {
- Shell::Bash | Shell::Zsh => format!(
+ Shell::Bash | Shell::Zsh => {
r#"if [[ "$-" == *i* ]] && [[ -t 0 ]] && [[ -t 1 ]]; then
_atuin_hex_tmux_current="${{TMUX:-}}"
_atuin_hex_tmux_previous="${{ATUIN_HEX_TMUX:-}}"
@@ -123,11 +106,9 @@ fn render_init(shell: Shell) -> String {
unset _atuin_hex_tmux_current _atuin_hex_tmux_previous
fi
-
-eval "$({init_command})"
"#
- ),
- Shell::Fish => format!(
+ }
+ Shell::Fish => {
r#"if status is-interactive; and test -t 0; and test -t 1
set -l _atuin_hex_tmux_current ""
if set -q TMUX
@@ -149,14 +130,13 @@ eval "$({init_command})"
exec atuin hex
end
end
-
-{init_command} | source
"#
- ),
+ }
// Nushell cannot dynamically source the output of `atuin init nu`,
// so we only output the hex preamble here. Users must also set up
// `atuin init nu` separately.
- Shell::Nu => r#"if (is-terminal --stdin) and (is-terminal --stdout) {
+ Shell::Nu => {
+ r#"if (is-terminal --stdin) and (is-terminal --stdout) {
let tmux_current = ($env.TMUX? | default "")
let tmux_previous = ($env.ATUIN_HEX_TMUX? | default "")
@@ -167,7 +147,7 @@ end
}
}
"#
- .to_string(),
+ }
}
}
@@ -452,7 +432,7 @@ mod app {
#[cfg(test)]
mod tests {
- use super::{Shell, init_command, render_init, shell_from_name};
+ use super::{Shell, render_init, shell_from_name};
#[test]
fn shell_from_name_handles_paths() {
@@ -463,24 +443,18 @@ mod tests {
}
#[test]
- fn init_command_is_bootstrap_only() {
- let command = init_command(Shell::Zsh);
- assert_eq!(command, "atuin init zsh");
- }
-
- #[test]
fn posix_init_uses_exec_and_tmux_guard() {
let script = render_init(Shell::Bash);
assert!(script.contains("exec atuin hex"));
assert!(script.contains("ATUIN_HEX_TMUX"));
- assert!(script.contains("eval \"$(atuin init bash)\""));
+ assert!(!script.contains("eval \"$(atuin init bash)\""));
}
#[test]
fn fish_init_uses_source() {
let script = render_init(Shell::Fish);
assert!(script.contains("exec atuin hex"));
- assert!(script.contains("atuin init fish | source"));
+ assert!(!script.contains("atuin init fish | source"));
}
#[test]
diff --git a/docs/docs/reference/hex.md b/docs/docs/reference/hex.md
new file mode 100644
index 00000000..1bbf9336
--- /dev/null
+++ b/docs/docs/reference/hex.md
@@ -0,0 +1,65 @@
+# hex
+
+Atuin Hex is an experimental lightweight PTY proxy, providing new features without needing to replace your existing terminal or shell. Atuin Hex currently supports bash, zsh, fish, and nu.
+
+## TUI Rendering
+
+The search TUI exposes a tradeoff: the UI is either in fullscreen alt-screen mode that takes over your terminal, or inline mode that clears your previous output. Neither is great.
+
+With Hex, we can have our cake AND eat it too. The Atuin popup renders over the top of your previous output, but when it's closed we can restore the output successfully.
+
+## Initialization
+
+Atuin Hex needs to be initialized separately from your existing Atuin config. Place the init line shown below in your shell's init script, as high in the document as possible, *before* your normal `atuin init` call.
+
+=== "zsh"
+
+ ```shell
+ eval "$(atuin hex init zsh)"
+ ```
+
+=== "bash"
+
+ ```shell
+ eval "$(atuin hex init bash)"
+ ```
+
+=== "fish"
+
+ Add
+
+ ```shell
+ atuin hex init fish | source
+ ```
+
+ to your `is-interactive` block in your `~/.config/fish/config.fish` file
+
+=== "Nushell"
+
+ Run in *Nushell*:
+
+ ```shell
+ mkdir ~/.local/share/atuin/
+ atuin hex init nu | save -f ~/.local/share/atuin/hex-init.nu
+ ```
+
+ Add to `config.nu`, **before** the regular `atuin init`:
+
+ ```shell
+ source ~/.local/share/atuin/hex-init.nu
+ ```
+ Nushell's `source` command requires a static file path, so you must
+ pre-generate the file.
+
+---
+
+If the `atuin` binary is not in your `PATH` by default, you should initialize Hex as soon as it is set. For example, for a bash user with Atuin installed in `~/.atuin/bin/atuin`, a config file might look like this:
+
+```bash
+export PATH=$HOME/.atuin/bin:$PATH
+eval "$(atuin hex init bash)"
+
+# ... other shell configuration ...
+
+eval "$(atuin init bash)"
+```
diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml
index 0c2445be..3a06643d 100644
--- a/docs/mkdocs.yml
+++ b/docs/mkdocs.yml
@@ -81,6 +81,7 @@ nav:
- doctor: reference/doctor.md
- daemon: reference/daemon.md
- gen-completions: reference/gen-completions.md
+ - hex: reference/hex.md
- import: reference/import.md
- info: reference/info.md
- history list: reference/list.md