Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate with fzf #68

Closed
neerajbadlani opened this issue May 8, 2021 · 25 comments
Closed

integrate with fzf #68

neerajbadlani opened this issue May 8, 2021 · 25 comments
Labels
bug Something isn't working

Comments

@neerajbadlani
Copy link

Unfortunately , I tried tui search , but still want to use fzf history search .
I am trying to integrate with fzf using history list , it throws following error .
Can u please help ?
Thanks

[master:.configfiles] atuin history list
Error: environment variable not found

Location:
src/command/history.rs:151:56

@conradludgate
Copy link
Collaborator

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

@conradludgate conradludgate added the bug Something isn't working label May 9, 2021
@ellie
Copy link
Member

ellie commented May 9, 2021

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

@ellie
Copy link
Member

ellie commented May 9, 2021

Hey @neerajbadlani!

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

atuin h l --cmd-only | fzf

@neerajbadlani
Copy link
Author

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.

@conradludgate
Copy link
Collaborator

conradludgate commented May 10, 2021

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

@neerajbadlani
Copy link
Author

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 ?

@ellie
Copy link
Member

ellie commented May 10, 2021

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

@thedrow
Copy link
Contributor

thedrow commented May 10, 2021

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

@Dentrax
Copy link

Dentrax commented Jun 12, 2021

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

@Dentrax
Copy link

Dentrax commented Oct 23, 2021

^ kind ping @ellie 🙏

@conradludgate
Copy link
Collaborator

@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

@hd-deman
Copy link

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?

@unai-ndz
Copy link

unai-ndz commented May 7, 2022

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"

@hd-deman
Copy link

hd-deman commented May 9, 2022

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

@jirutka
Copy link
Contributor

jirutka commented May 14, 2022

@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?

@panekj
Copy link
Contributor

panekj commented May 14, 2022

It was mentioned here already: #286

@iloveitaly
Copy link
Contributor

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

@cocoonkid
Copy link

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!

@jquick
Copy link

jquick commented Jun 8, 2023

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

@raghuAtRA
Copy link

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.

@iloveitaly
Copy link
Contributor

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 :(

@nicoandmee
Copy link
Contributor

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

@conradludgate
Copy link
Collaborator

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

@alcroito
Copy link

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.

This worked for me

        local fzf_opts=(
            --height=${FZF_TMUX_HEIGHT:-80%}
            --tac
            "-n2..,.."
            --tiebreak=index
            "--query=${LBUFFER}"
            "+m"
            '--preview=echo {}'
            "--preview-window=down:3:hidden:wrap"
            "--bind=?:toggle-preview"
            "--bind=ctrl-d:reload(atuin search $atuin_opts -c $PWD),ctrl-r:reload(atuin search $atuin_opts)"
        )

@DieracDelta
Copy link

DieracDelta commented Feb 6, 2024

Does anyone have fzf working with atuin and fish? It seems like that script is zsh only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests