Code Monkey home page Code Monkey logo

Comments (23)

jquick avatar jquick commented on May 18, 2024 6

if you only use zsh-autosuggestions this works:

# zsh autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
bindkey '^ ' autosuggest-accept
_zsh_autosuggest_strategy_atuin_top() {
    suggestion=$(atuin search --cmd-only --limit 1 --search-mode prefix $1)
}
ZSH_AUTOSUGGEST_STRATEGY=atuin_top

from atuin.

cocoonkid avatar cocoonkid commented on May 18, 2024 5

I found https://news.ycombinator.com/item?id=35256206

reposting here for brevity:

atuin-setup() {
        if ! which atuin &> /dev/null; then return 1; fi
        bindkey '^E' _atuin_search_widget

        export ATUIN_NOBIND="true"
        eval "$(atuin init "$CUR_SHELL")"
        fzf-atuin-history-widget() {
            local selected num
            setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2>/dev/null

            # local atuin_opts="--cmd-only --limit ${ATUIN_LIMIT:-5000}"
            local atuin_opts="--cmd-only"
            local fzf_opts=(
                --height=${FZF_TMUX_HEIGHT:-80%}
                --tac
                "-n2..,.."
                --tiebreak=index
                "--query=${LBUFFER}"
                "+m"
                "--bind=ctrl-d:reload(atuin search $atuin_opts -c $PWD),ctrl-r:reload(atuin search $atuin_opts)"
            )

            selected=$(
                eval "atuin search ${atuin_opts}" |
                    fzf "${fzf_opts[@]}"
            )
            local ret=$?
            if [ -n "$selected" ]; then
                # the += lets it insert at current pos instead of replacing
                LBUFFER+="${selected}"
            fi
            zle reset-prompt
            return $ret
        }
        zle -N fzf-atuin-history-widget
        bindkey '^R' fzf-atuin-history-widget
    }
    atuin-setup

This works really well so far!

from atuin.

conradludgate avatar conradludgate commented on May 18, 2024 3

@Dentrax I believe what you want is possible, although I don't know the details of how to configure the hook correctly.

This command does what you want,

atuin history list --cmd-only | fzf

Now, if you set export ATUIN_NOBIND=1 in your .rc file before the atuin init step, then the TUI based hook won't be installed, and you could install your own to trigger the command I suggested above.

There's a secondary issue that atuin streaming to fzf is slow but I'm gonna close this issue as solved and open a new one for that

from atuin.

unai-ndz avatar unai-ndz commented on May 18, 2024 3

I have atuin working with fzf and zsh-autosuggestions
I don't have the time to review it now, or to publish my entire dotfiles but I can dump the important bits. Some of it is a little messy but it's decently documented.
Pastebin

@hd-deman You can write stuff into the shell input by setting it in the buffer like this: BUFFER="some stuff"

from atuin.

conradludgate avatar conradludgate commented on May 18, 2024 3

#1274 which should be out next week should help with that

from atuin.

conradludgate avatar conradludgate commented on May 18, 2024 2

cargo install --path . --root $(brew --prefix) cargo install atuin --root $(brew --prefix) should do the trick

from atuin.

panekj avatar panekj commented on May 18, 2024 2

It was mentioned here already: #286

from atuin.

raghuAtRA avatar raghuAtRA commented on May 18, 2024 2

I found https://news.ycombinator.com/item?id=35256206

reposting here for brevity:

atuin-setup() {
        if ! which atuin &> /dev/null; then return 1; fi
        bindkey '^E' _atuin_search_widget

        export ATUIN_NOBIND="true"
        eval "$(atuin init "$CUR_SHELL")"
        fzf-atuin-history-widget() {
            local selected num
            setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2>/dev/null

            # local atuin_opts="--cmd-only --limit ${ATUIN_LIMIT:-5000}"
            local atuin_opts="--cmd-only"
            local fzf_opts=(
                --height=${FZF_TMUX_HEIGHT:-80%}
                --tac
                "-n2..,.."
                --tiebreak=index
                "--query=${LBUFFER}"
                "+m"
                "--bind=ctrl-d:reload(atuin search $atuin_opts -c $PWD),ctrl-r:reload(atuin search $atuin_opts)"
            )

            selected=$(
                eval "atuin search ${atuin_opts}" |
                    fzf "${fzf_opts[@]}"
            )
            local ret=$?
            if [ -n "$selected" ]; then
                # the += lets it insert at current pos instead of replacing
                LBUFFER+="${selected}"
            fi
            zle reset-prompt
            return $ret
        }
        zle -N fzf-atuin-history-widget
        bindkey '^R' fzf-atuin-history-widget
    }
    atuin-setup

This works really well so far!

Works really well - but how do I get the preview window? I tried adding "--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'" to the fzf_opts but that doesn't change anything.

from atuin.

iloveitaly avatar iloveitaly commented on May 18, 2024 2

Has anyone been able to get this working properly with multiline shell history? If there's a history command that is multiline, it shows up as multiple entries in the fzf list, which makes this fzf-based search unusable :(

from atuin.

thedrow avatar thedrow commented on May 18, 2024 1

Maybe we should ask fzf's maintainers to detect if atuin is in the path and use that instead of history.

from atuin.

Dentrax avatar Dentrax commented on May 18, 2024 1

I'm looking forward to this feature! @ellie Each time I write a command and press the UP key to auto-complete current cmd, TUI appears and I had a bit distracting DX. It would be great if we are able to use it with fzf feature enabled only. 😇

i.e. something like the following, but atuin powered. :)

Screen Shot 2021-06-12 at 13 05 18

from atuin.

jirutka avatar jirutka commented on May 18, 2024 1

@ellie, there’s a better alternative to fzf written in Rust: skim. Unlike fzf, it can be used as a library, so maybe it’d make sense to integrate it into atuin?

from atuin.

conradludgate avatar conradludgate commented on May 18, 2024

Yeah that seems to be a bug. It's looking for the ATUIN_SESSION environment variable, even though its not needed in your example

from atuin.

ellie avatar ellie commented on May 18, 2024

Yup the bug is with the bash script! The ATUIN_SESSION variable is actually needed for history to be properly recorded though, so I'll get the bash plugin fixed.

As well as that, you'll probably want a nice way of listing only the command for fzf, so that'll need sorting too

from atuin.

ellie avatar ellie commented on May 18, 2024

Hey @neerajbadlani!

Once #89 merges, you should be able to do something like this

atuin h l --cmd-only | fzf

from atuin.

neerajbadlani avatar neerajbadlani commented on May 18, 2024

Thanks @ellie , above works and is close to what i want . However I see duplicate entries in history .

Also , new to rust ecosystem , since brew install --HEAD dint work , so had to do manual installation .
How do i tell rust to install in specific directory ?

[main:atuin] cargo install --root $(brew --prefix)
error: Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package.

from atuin.

neerajbadlani avatar neerajbadlani commented on May 18, 2024

Thanks , I am able to integrate it with fzf properly now , exactly similar to what fzf provides , but with machine machine and session sync .
2 things remaining : 1 . Duplicate Entries 2 . Sorted Histories ( Recent , Frequency , .. )
Should I close this and open another issue for those ?

from atuin.

ellie avatar ellie commented on May 18, 2024

Something like this should work :)

https://stackoverflow.com/questions/11532157/remove-duplicate-lines-without-sorting

We could add a unique flag, but I'd rather not unless it's 100% necessary

Another issue for sorted history would be good! I've been thinking of how we can better prioritise things

from atuin.

Dentrax avatar Dentrax commented on May 18, 2024

^ kind ping @ellie 🙏

from atuin.

hd-deman avatar hd-deman commented on May 18, 2024

this thing works

export ATUIN_NOBIND="true"
eval "$(atuin init zsh)"

zle -N _atuinr_widget _atuinr

_atuinr() {
    atuin history list --cmd-only | fzf
}
bindkey '^r' _atuinr_widget

The only difference is that it immediately executes the code instead of put it into the shell input.
I don't understand how to fix it.
any ideas?

from atuin.

hd-deman avatar hd-deman commented on May 18, 2024

your

I have atuin working with fzf and zsh-autosuggestions I don't have the time to review it now, or to publish my entire dotfiles but I can dump the important bits. Some of it is a little messy but it's decently documented. Pastebin

@hd-deman You can write stuff into the shell input by setting it in the buffer like this: BUFFER="some stuff"

Perfect. just what I needed. Thanks

from atuin.

iloveitaly avatar iloveitaly commented on May 18, 2024

This doesn't work for multiline entries in the shell history. Has anyone been able to solve that?

from atuin.

nicoandmee avatar nicoandmee commented on May 18, 2024

Has anyone been able to get this working properly with multiline shell history? If there's a history command that is multiline, it shows up as multiple entries in the fzf list, which makes this fzf-based search unusable :(

Also wondering this

from atuin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.