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 { pub fn is_zsh() -> bool {
// only set on zsh // 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)] #[cfg(test)]

View file

@ -703,9 +703,10 @@ pub async fn history(
if index < results.len() { if index < results.len() {
let mut command = results.swap_remove(index).command; 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; command = String::from("__atuin_accept__:") + &command;
} }
// index is in bounds so we return that entry // index is in bounds so we return that entry
Ok(command) Ok(command)
} else if index == RETURN_ORIGINAL { } else if index == RETURN_ORIGINAL {

View file

@ -8,19 +8,26 @@ end
function _atuin_postexec --on-event fish_postexec function _atuin_postexec --on-event fish_postexec
set s $status set s $status
if test -n "$ATUIN_HISTORY_ID" if test -n "$ATUIN_HISTORY_ID"
ATUIN_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null & ATUIN_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null &
disown disown
end end
set --erase ATUIN_HISTORY_ID set --erase ATUIN_HISTORY_ID
end end
function _atuin_search 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 commandline -f repaint
if test -n "$h" 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" commandline -r "$h"
end end
end
end end
function _atuin_bind_up 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 # Only invoke atuin if we're on the top line of the command
set -l lineno (commandline --line) set -l lineno (commandline --line)
switch $lineno switch $lineno
case 1 case 1
_atuin_search --shell-up-key-binding _atuin_search --shell-up-key-binding

View file

@ -10,7 +10,6 @@
autoload -U add-zsh-hook autoload -U add-zsh-hook
export ATUIN_SESSION=$(atuin uuid) export ATUIN_SESSION=$(atuin uuid)
export ATUIN_HISTORY="atuin history list"
_atuin_preexec() { _atuin_preexec() {
local id local id
@ -34,7 +33,7 @@ _atuin_search() {
# swap stderr and stdout, so that the tui stuff works # swap stderr and stdout, so that the tui stuff works
# TODO: not this # TODO: not this
# shellcheck disable=SC2048 # 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 zle reset-prompt

View file

@ -309,7 +309,7 @@ remote sync server. Any longer than this and the request will fail.
## enter_accept ## enter_accept
Default: false 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 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 than the user having to press enter twice. Pressing tab will return to the