Add fish support for enter_accept (#1315)

* Add fish support for `enter_accept`

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

* Document
This commit is contained in:
Ellie Huxtable 2023-10-20 07:57:29 +01:00 committed by GitHub
parent 88f3e2a04f
commit 2f9df9350d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 7 deletions

View file

@ -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)]

View file

@ -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 {

View file

@ -8,19 +8,26 @@ 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"
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
function _atuin_bind_up
@ -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

View file

@ -10,7 +10,6 @@
autoload -U add-zsh-hook
export ATUIN_SESSION=$(atuin uuid)
export ATUIN_HISTORY="atuin history list"
_atuin_preexec() {
local id
@ -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

View file

@ -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