aboutsummaryrefslogtreecommitdiffstats
path: root/src/shell/atuin.fish
blob: 95074b0e9c6205abb1d6fa4e9b4da5e4e8c35f77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
set -gx ATUIN_SESSION (atuin uuid)

function _atuin_preexec --on-event fish_preexec
    set -gx ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
end

function _atuin_postexec --on-event fish_postexec
    set s $status
    if test -n "$ATUIN_HISTORY_ID"
        RUST_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null &
        disown
    end
end

function _atuin_search
    set h (RUST_LOG=error atuin search -i -- (commandline -b) 3>&1 1>&2 2>&3)
    commandline -f repaint
    if test -n "$h"
        commandline -r $h
    end
end

function _atuin_suppress_tui
    set -gx ATUIN_SUPPRESS_TUI "true"
end

function _atuin_unsuppress_tui
    set -ge ATUIN_SUPPRESS_TUI
end

function _atuin_bind_up
    if test -z $ATUIN_SUPPRESS_TUI
        _atuin_search
    else
        up-or-search
    end
end

if test -z $ATUIN_NOBIND
    bind \cr _atuin_search
    bind -k up _atuin_bind_up
    bind \eOA _atuin_bind_up
    bind \e\[A _atuin_bind_up
    bind \t 'commandline -f complete && _atuin_suppress_tui'
    bind \e 'commandline -f cancel && _atuin_unsuppress_tui'
    bind \r 'commandline -f execute && _atuin_unsuppress_tui'
    bind \n 'commandline -f execute && _atuin_unsuppress_tui'


    if bind -M insert > /dev/null 2>&1
        bind -M insert \cr _atuin_search
        bind -M insert -k up _atuin_bind_up
        bind -M insert \eOA _atuin_bind_up
        bind -M insert \e\[A _atuin_bind_up
        bind -M insert \t 'commandline -f complete && _atuin_suppress_tui'
        bind -M insert \e 'commandline -f cancel && _atuin_unsuppress_tui'
        bind -M insert \r 'commandline -f execute && _atuin_unsuppress_tui'
        bind -M insert \n 'commandline -f execute && _atuin_unsuppress_tui'
    end
end