junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.79k stars 2.38k forks source link

Its Possible Copy To Clipboard ? #2323

Closed pwndumb closed 3 years ago

pwndumb commented 3 years ago

Info

Problem / Steps to reproduce

I cant copy select line in fzf to my clipboard. I Just try a lot of combinations but not work. The default key CTRL+R never work. . I use this option

export FZF_DEFAULT_OPTS="
--layout=reverse
--info=inline
--height=80%
--multi
--preview-window=:hidden
--preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--color='hl:148,hl+:154,pointer:032,marker:010,bg+:237,gutter:008'
--prompt='∼ ' --pointer='▶' --marker='✓'
--bind '?:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | xclip)'
--bind 'ctrl-e:execute(echo {+} | xargs -o vim)'
--bind 'ctrl-v:execute(code {+})'
"
rogerdahl commented 3 years ago

By default, xclip copies to X primary selection, XA_PRIMARY which is not where most apps expect to find clipboard data. To copy to the clipboard, XA_CLIPBOARD, with Ctrl-Y, use `--bind 'ctrl-y:execute-silent(echo {+} | xclip -se c)'.

Sy3Omda commented 3 years ago

By default, xclip copies to X primary selection, XA_PRIMARY which is not where most apps expect to find clipboard data. To copy to the clipboard, XA_CLIPBOARD, with Ctrl-Y, use `--bind 'ctrl-y:execute-silent(echo {+} | xclip -se c)'.

i tried this method but it`s not working my Q is how to copy text from terminal ? i am using ctrl shift space for marking text Thank you so much @rogerdahl

rogerdahl commented 3 years ago

@Sy3Omda That's a different question altogether and depends on your terminal emulator and which keyboard shortcuts it has. Have you tried right-clicking the marked text?

imambungo commented 2 years ago

I used this:

# Use like normal fzf, but the output are copied to the clipboard
f()
{
    # https://stackoverflow.com/a/46726373/9157799
    if [ -p /dev/stdin ]  # if data was piped
    then
        stdin=$(</dev/stdin)
        echo "$stdin" | fzf "$@" | xclip
        fzo="$(xclip -o)"
    else
        fzo=$(fzf "$@")
    fi
    if [ "$fzo" != "" ]
    then
        echo -n "$fzo" | xclip -se c
        echo "$fzo"
    fi
}

You can use it like an alias of fzf e.g. cat list | f

Sy3Omda commented 2 years ago

@imambungo Thx for this tip but i mean here to high-lite desired text in terminal (terminator) and with key binding copy it or just ctrl + shift + c to copy it, all this by using only keyboard not mouse.

imambungo commented 2 years ago

@Sy3Omda I don't know how to do that in terminator but you can use tmux to do that.

pnchinmay commented 2 years ago

I tried several options and these worked out for me. This might help someone looking for these.

--bind 'ctrl-y:execute(readlink -f {} | xclip -selection clipboard)'
--bind 'ctrl-alt-y:execute-silent(xclip -selection clipboard {})'
dualfade commented 1 year ago

Just adding here; Thank for all this !

w/ zsh --

This is working for me with xclip -- --bind 'ctrl-y:execute(readlink -f {} | echo -n {2..} | xclip -selection clipboard)'