aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-10-20 07:57:29 +0100
committerGitHub <noreply@github.com>2023-10-20 07:57:29 +0100
commit2f9df9350d5b645c867a440e63071d323fd53409 (patch)
tree81c35715b3122726edf32221f65425b547538bed
parentAdd enter_accept to immediately execute an accepted command (#1311) (diff)
downloadatuin-2f9df9350d5b645c867a440e63071d323fd53409.zip
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
-rw-r--r--atuin-common/src/utils.rs7
-rw-r--r--atuin/src/command/client/search/interactive.rs3
-rw-r--r--atuin/src/shell/atuin.fish12
-rw-r--r--atuin/src/shell/atuin.zsh3
-rw-r--r--docs/docs/config/config.md2
5 files changed, 20 insertions, 7 deletions
diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs
index cd2cd4dc..65fa40cf 100644
--- a/atuin-common/src/utils.rs
+++ b/atuin-common/src/utils.rs
@@ -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)]
diff --git a/atuin/src/command/client/search/interactive.rs b/atuin/src/command/client/search/interactive.rs
index bfee81d4..d900433e 100644
--- a/atuin/src/command/client/search/interactive.rs
+++ b/atuin/src/command/client/search/interactive.rs
@@ -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 {
diff --git a/atuin/src/shell/atuin.fish b/atuin/src/shell/atuin.fish
index 5b7b64e8..2f007fcf 100644
--- a/atuin/src/shell/atuin.fish
+++ b/atuin/src/shell/atuin.fish
@@ -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
@@ -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
diff --git a/atuin/src/shell/atuin.zsh b/atuin/src/shell/atuin.zsh
index 19941bed..44dda4fe 100644
--- a/atuin/src/shell/atuin.zsh
+++ b/atuin/src/shell/atuin.zsh
@@ -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
diff --git a/docs/docs/config/config.md b/docs/docs/config/config.md
index 5cdbe922..90f4fe51 100644
--- a/docs/docs/config/config.md
+++ b/docs/docs/config/config.md
@@ -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