Skip to content

Commit

Permalink
Add fish support for enter_accept (#1315)
Browse files Browse the repository at this point in the history
* Add fish support for `enter_accept`

Also fixes shell detection. Who trusted me to write jetlagged code last
night huh?

* Document
  • Loading branch information
ellie authored Oct 20, 2023
1 parent 88f3e2a commit 2f9df93
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
7 changes: 6 additions & 1 deletion atuin-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ pub fn get_current_dir() -> String {

pub fn is_zsh() -> bool {
// only set on zsh
env::var("ZSH_VERSION").is_ok()
env::var("ATUIN_SHELL_ZSH").is_ok()
}

pub fn is_fish() -> bool {
// only set on zsh
env::var("ATUIN_SHELL_FISH").is_ok()
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,10 @@ pub async fn history(

if index < results.len() {
let mut command = results.swap_remove(index).command;
if accept && utils::is_zsh() {
if accept && (utils::is_zsh() || utils::is_fish()) {
command = String::from("__atuin_accept__:") + &command;
}

// index is in bounds so we return that entry
Ok(command)
} else if index == RETURN_ORIGINAL {
Expand Down
12 changes: 10 additions & 2 deletions atuin/src/shell/atuin.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ end

function _atuin_postexec --on-event fish_postexec
set s $status

if test -n "$ATUIN_HISTORY_ID"
ATUIN_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null &
disown
end

set --erase ATUIN_HISTORY_ID
end

function _atuin_search
set h (ATUIN_LOG=error atuin search $argv -i -- (commandline -b) 3>&1 1>&2 2>&3)
set h (ATUIN_SHELL_FISH=t ATUIN_LOG=error atuin search $argv -i -- (commandline -b) 3>&1 1>&2 2>&3)
commandline -f repaint

if test -n "$h"
commandline -r "$h"
if string match -g '__atuin_accept__:*' "$h"
eval (string match -r '__atuin_accept__:(.*|\s*)' "$h" | awk 'NR == 2')
else
commandline -r "$h"
end
end
end

Expand All @@ -32,6 +39,7 @@ function _atuin_bind_up

# Only invoke atuin if we're on the top line of the command
set -l lineno (commandline --line)

switch $lineno
case 1
_atuin_search --shell-up-key-binding
Expand Down
3 changes: 1 addition & 2 deletions atuin/src/shell/atuin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
autoload -U add-zsh-hook

export ATUIN_SESSION=$(atuin uuid)
export ATUIN_HISTORY="atuin history list"

_atuin_preexec() {
local id
Expand All @@ -34,7 +33,7 @@ _atuin_search() {
# swap stderr and stdout, so that the tui stuff works
# TODO: not this
# shellcheck disable=SC2048
output=$(ATUIN_LOG=error atuin search $* -i -- $BUFFER 3>&1 1>&2 2>&3)
output=$(ATUIN_SHELL_ZSH=t ATUIN_LOG=error atuin search $* -i -- $BUFFER 3>&1 1>&2 2>&3)

zle reset-prompt

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ remote sync server. Any longer than this and the request will fail.
## enter_accept
Default: false

Only supported on Zsh.
Only supported on Zsh and Fish.

When set to true, Atuin will default to immediately executing a command rather
than the user having to press enter twice. Pressing tab will return to the
Expand Down

1 comment on commit 2f9df93

@vercel
Copy link

@vercel vercel bot commented on 2f9df93 Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

atuin-docs – ./

atuin-docs.vercel.app
atuin-docs-git-main-atuin.vercel.app
atuin-docs-atuin.vercel.app

Please sign in to comment.