Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 11 additions & 37 deletions crates/atuin-hex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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:-}}"
Expand All @@ -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
Expand All @@ -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 "")

Expand All @@ -167,7 +147,7 @@ end
}
}
"#
.to_string(),
}
}
}

Expand Down Expand Up @@ -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() {
Expand All @@ -462,25 +442,19 @@ mod tests {
assert_eq!(shell_from_name("nu"), Some(Shell::Nu));
}

#[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]
Expand Down
65 changes: 65 additions & 0 deletions docs/docs/reference/hex.md
Original file line number Diff line number Diff line change
@@ -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)"
```
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down