Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions crates/atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,17 +1532,29 @@ impl Stdout {
impl Drop for Stdout {
fn drop(&mut self) {
#[cfg(not(target_os = "windows"))]
execute!(self.writer, PopKeyboardEnhancementFlags).unwrap();
if let Err(e) = execute!(self.writer, PopKeyboardEnhancementFlags) {
tracing::error!(?e, "Failed to pop keyboard enhancement flags");
}

if !self.inline_mode {
execute!(self.writer, terminal::LeaveAlternateScreen).unwrap();
if !self.inline_mode
&& let Err(e) = execute!(self.writer, terminal::LeaveAlternateScreen)
{
tracing::error!(?e, "Failed to leave alt screen mode");
}
if !self.no_mouse {
execute!(self.writer, event::DisableMouseCapture).unwrap();

if !self.no_mouse
&& let Err(e) = execute!(self.writer, event::DisableMouseCapture)
{
tracing::error!(?e, "Failed to disable mouse capture");
}
execute!(self.writer, event::DisableBracketedPaste).unwrap();

terminal::disable_raw_mode().unwrap();
if let Err(e) = execute!(self.writer, event::DisableBracketedPaste) {
tracing::error!(?e, "Failed to disable bracketed paste");
}

if let Err(e) = terminal::disable_raw_mode() {
tracing::error!(?e, "Failed to disable raw mode");
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions crates/atuin/src/shell/atuin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ __atuin_search_cmd() {
__atuin_tmux_popup_cleanup
trap - EXIT HUP INT TERM
else
ATUIN_SHELL=bash ATUIN_LOG=error ATUIN_QUERY=$READLINE_LINE atuin search "${search_args[@]}" -i 3>&1 1>&2 2>&3
ATUIN_SHELL=bash ATUIN_LOG=error ATUIN_QUERY=$READLINE_LINE atuin search "${search_args[@]}" -i 3>&1 1>&2 2>&3 3>&-
fi
}

Expand Down Expand Up @@ -329,7 +329,10 @@ __atuin_history() {
READLINE_LINE="" READLINE_POINT=0

local __atuin_output
__atuin_output=$(__atuin_search_cmd "$@")
if ! __atuin_output=$(__atuin_search_cmd "$@"); then
[[ $__atuin_output ]] && printf '%s\n' "$__atuin_output" >&2
return 1
fi

# We do nothing when the search is canceled.
[[ $__atuin_output ]] || return 0
Expand Down
14 changes: 12 additions & 2 deletions crates/atuin/src/shell/atuin.fish
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ function _atuin_search
set -l use_tmux_popup (_atuin_tmux_popup_check)

set -l ATUIN_H
set -l ATUIN_STATUS 0
if test "$use_tmux_popup" -eq 1
set -l tmpdir (mktemp -d)
if not test -d "$tmpdir"
# if mktemp got errors
set ATUIN_H (ATUIN_SHELL=fish ATUIN_LOG=error ATUIN_QUERY=(commandline -b) atuin search --keymap-mode=$keymap_mode $argv -i 3>&1 1>&2 2>&3 | string collect)
set ATUIN_H (ATUIN_SHELL=fish ATUIN_LOG=error ATUIN_QUERY=(commandline -b) atuin search --keymap-mode=$keymap_mode $argv -i 3>&1 1>&2 2>&3 3>&- | string collect)
set ATUIN_STATUS $pipestatus[1]
else
set -l result_file "$tmpdir/result"

Expand All @@ -102,6 +104,7 @@ function _atuin_search
set -l popup_height (test -n "$ATUIN_TMUX_POPUP_HEIGHT" && echo "$ATUIN_TMUX_POPUP_HEIGHT" || echo "60%")
tmux display-popup -d "$cdir" -w "$popup_width" -h "$popup_height" -E -E -- \
sh -c "PATH='$PATH' ATUIN_SESSION='$ATUIN_SESSION' ATUIN_SHELL=fish ATUIN_LOG=error ATUIN_QUERY='$query' atuin search --keymap-mode=$keymap_mode$escaped_args -i 2>'$result_file'"
set ATUIN_STATUS $status

if test -f "$result_file"
set ATUIN_H (cat "$result_file" | string collect)
Expand All @@ -113,7 +116,14 @@ function _atuin_search
# In fish 3.4 and above we can use `"$(some command)"` to keep multiple lines separate;
# but to support fish 3.3 we need to use `(some command | string collect)`.
# https://fishshell.com/docs/current/relnotes.html#id24 (fish 3.4 "Notable improvements and fixes")
set ATUIN_H (ATUIN_SHELL=fish ATUIN_LOG=error ATUIN_QUERY=(commandline -b) atuin search --keymap-mode=$keymap_mode $argv -i 3>&1 1>&2 2>&3 | string collect)
set ATUIN_H (ATUIN_SHELL=fish ATUIN_LOG=error ATUIN_QUERY=(commandline -b) atuin search --keymap-mode=$keymap_mode $argv -i 3>&1 1>&2 2>&3 3>&- | string collect)
set ATUIN_STATUS $pipestatus[1]
end

if test "$ATUIN_STATUS" -ne 0
test -n "$ATUIN_H"; and printf '%s\n' "$ATUIN_H" >&2
commandline -f repaint
return "$ATUIN_STATUS"
end

set ATUIN_H (string trim -- $ATUIN_H | string collect) # trim whitespace
Expand Down
10 changes: 8 additions & 2 deletions crates/atuin/src/shell/atuin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ __atuin_search_cmd() {
__atuin_tmux_popup_cleanup
trap - EXIT HUP INT TERM
else
ATUIN_SHELL=zsh ATUIN_LOG=error ATUIN_QUERY=$BUFFER atuin search "${search_args[@]}" -i 3>&1 1>&2 2>&3
ATUIN_SHELL=zsh ATUIN_LOG=error ATUIN_QUERY=$BUFFER atuin search "${search_args[@]}" -i 3>&1 1>&2 2>&3 3>&-
fi
}

Expand All @@ -119,15 +119,21 @@ _atuin_search() {

# swap stderr and stdout, so that the tui stuff works
# TODO: not this
local output
local output __atuin_status
# shellcheck disable=SC2048
output=$(__atuin_search_cmd $*)
__atuin_status=$?

zle reset-prompt
# re-enable bracketed paste
# shellcheck disable=SC2154
echo -n ${zle_bracketed_paste[1]} >/dev/tty

if (( __atuin_status != 0 )); then
[[ -n $output ]] && print -r -- "$output" >/dev/tty
return $__atuin_status
fi

Comment thread
BinaryMuse marked this conversation as resolved.
if [[ -n $output ]]; then
RBUFFER=""
LBUFFER=$output
Expand Down
Loading