Skip to content

Commit 640beb3

Browse files
authored
fix: Don't run 'atuin init' in 'atuin hex init' — each must be initialized separately (#3334)
1 parent 7f06ba0 commit 640beb3

File tree

3 files changed

+77
-37
lines changed

3 files changed

+77
-37
lines changed

crates/atuin-hex/src/lib.rs

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ enum Shell {
2929
Nu,
3030
}
3131

32-
impl Shell {
33-
fn as_str(self) -> &'static str {
34-
match self {
35-
Self::Bash => "bash",
36-
Self::Zsh => "zsh",
37-
Self::Fish => "fish",
38-
Self::Nu => "nu",
39-
}
40-
}
41-
}
42-
4332
impl Init {
4433
fn run(self) -> Result<(), String> {
4534
let shell = detect_shell(self.shell)?;
@@ -102,15 +91,9 @@ fn shell_from_name(name: &str) -> Option<Shell> {
10291
}
10392
}
10493

105-
fn init_command(shell: Shell) -> String {
106-
format!("atuin init {}", shell.as_str())
107-
}
108-
109-
fn render_init(shell: Shell) -> String {
110-
let init_command = init_command(shell);
111-
94+
fn render_init(shell: Shell) -> &'static str {
11295
match shell {
113-
Shell::Bash | Shell::Zsh => format!(
96+
Shell::Bash | Shell::Zsh => {
11497
r#"if [[ "$-" == *i* ]] && [[ -t 0 ]] && [[ -t 1 ]]; then
11598
_atuin_hex_tmux_current="${{TMUX:-}}"
11699
_atuin_hex_tmux_previous="${{ATUIN_HEX_TMUX:-}}"
@@ -123,11 +106,9 @@ fn render_init(shell: Shell) -> String {
123106
124107
unset _atuin_hex_tmux_current _atuin_hex_tmux_previous
125108
fi
126-
127-
eval "$({init_command})"
128109
"#
129-
),
130-
Shell::Fish => format!(
110+
}
111+
Shell::Fish => {
131112
r#"if status is-interactive; and test -t 0; and test -t 1
132113
set -l _atuin_hex_tmux_current ""
133114
if set -q TMUX
@@ -149,14 +130,13 @@ eval "$({init_command})"
149130
exec atuin hex
150131
end
151132
end
152-
153-
{init_command} | source
154133
"#
155-
),
134+
}
156135
// Nushell cannot dynamically source the output of `atuin init nu`,
157136
// so we only output the hex preamble here. Users must also set up
158137
// `atuin init nu` separately.
159-
Shell::Nu => r#"if (is-terminal --stdin) and (is-terminal --stdout) {
138+
Shell::Nu => {
139+
r#"if (is-terminal --stdin) and (is-terminal --stdout) {
160140
let tmux_current = ($env.TMUX? | default "")
161141
let tmux_previous = ($env.ATUIN_HEX_TMUX? | default "")
162142
@@ -167,7 +147,7 @@ end
167147
}
168148
}
169149
"#
170-
.to_string(),
150+
}
171151
}
172152
}
173153

@@ -452,7 +432,7 @@ mod app {
452432

453433
#[cfg(test)]
454434
mod tests {
455-
use super::{Shell, init_command, render_init, shell_from_name};
435+
use super::{Shell, render_init, shell_from_name};
456436

457437
#[test]
458438
fn shell_from_name_handles_paths() {
@@ -462,25 +442,19 @@ mod tests {
462442
assert_eq!(shell_from_name("nu"), Some(Shell::Nu));
463443
}
464444

465-
#[test]
466-
fn init_command_is_bootstrap_only() {
467-
let command = init_command(Shell::Zsh);
468-
assert_eq!(command, "atuin init zsh");
469-
}
470-
471445
#[test]
472446
fn posix_init_uses_exec_and_tmux_guard() {
473447
let script = render_init(Shell::Bash);
474448
assert!(script.contains("exec atuin hex"));
475449
assert!(script.contains("ATUIN_HEX_TMUX"));
476-
assert!(script.contains("eval \"$(atuin init bash)\""));
450+
assert!(!script.contains("eval \"$(atuin init bash)\""));
477451
}
478452

479453
#[test]
480454
fn fish_init_uses_source() {
481455
let script = render_init(Shell::Fish);
482456
assert!(script.contains("exec atuin hex"));
483-
assert!(script.contains("atuin init fish | source"));
457+
assert!(!script.contains("atuin init fish | source"));
484458
}
485459

486460
#[test]

docs/docs/reference/hex.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# hex
2+
3+
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.
4+
5+
## TUI Rendering
6+
7+
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.
8+
9+
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.
10+
11+
## Initialization
12+
13+
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.
14+
15+
=== "zsh"
16+
17+
```shell
18+
eval "$(atuin hex init zsh)"
19+
```
20+
21+
=== "bash"
22+
23+
```shell
24+
eval "$(atuin hex init bash)"
25+
```
26+
27+
=== "fish"
28+
29+
Add
30+
31+
```shell
32+
atuin hex init fish | source
33+
```
34+
35+
to your `is-interactive` block in your `~/.config/fish/config.fish` file
36+
37+
=== "Nushell"
38+
39+
Run in *Nushell*:
40+
41+
```shell
42+
mkdir ~/.local/share/atuin/
43+
atuin hex init nu | save -f ~/.local/share/atuin/hex-init.nu
44+
```
45+
46+
Add to `config.nu`, **before** the regular `atuin init`:
47+
48+
```shell
49+
source ~/.local/share/atuin/hex-init.nu
50+
```
51+
Nushell's `source` command requires a static file path, so you must
52+
pre-generate the file.
53+
54+
---
55+
56+
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:
57+
58+
```bash
59+
export PATH=$HOME/.atuin/bin:$PATH
60+
eval "$(atuin hex init bash)"
61+
62+
# ... other shell configuration ...
63+
64+
eval "$(atuin init bash)"
65+
```

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ nav:
8181
- doctor: reference/doctor.md
8282
- daemon: reference/daemon.md
8383
- gen-completions: reference/gen-completions.md
84+
- hex: reference/hex.md
8485
- import: reference/import.md
8586
- info: reference/info.md
8687
- history list: reference/list.md

0 commit comments

Comments
 (0)