Fzf: ZSH: Save output of reversed searched command in clipboard (via xclip) when type CTRL+Y

Created on 20 Nov 2018  路  2Comments  路  Source: junegunn/fzf

  • Category

    • [x] fzf binary

    • [ ] fzf-tmux script

    • [x] Key bindings

    • [ ] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [x] Linux

    • [ ] Mac OS X

    • [ ] Windows

    • [ ] Windows Subsystem for Linux

    • [ ] Etc.

  • Shell

    • [ ] bash

    • [x] zsh

    • [ ] fish

      Hello,

      is there way how to print output of reversed searched command in stodut and save it into clipboard (use _xclip_) when I type CTRL+Y key?
      I imagine that this option will be saved in FZF_CTRL_R_OPTS variable.

      Thx for your answer!

question tip

Most helpful comment

Here is my FZF_CTRL_R_OPTS

export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --header 'Press CTRL-Y to copy command into clipboard' --border"
  • CTRL-Y to copy the command to clipboard using pbcopy and exit (abort)

    • I'm not familiar with xclip, but it should be similar

  • ? key to open preview window on the bottom to see long commands that don't fit in one line
  • --border for cosmetic reasons

All 2 comments

Here is my FZF_CTRL_R_OPTS

export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --header 'Press CTRL-Y to copy command into clipboard' --border"
  • CTRL-Y to copy the command to clipboard using pbcopy and exit (abort)

    • I'm not familiar with xclip, but it should be similar

  • ? key to open preview window on the bottom to see long commands that don't fit in one line
  • --border for cosmetic reasons

I was looking for this same functionality, lucky to find it here!
I enabled it in bash as:

export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | xclip -selection clipboard; sleep 0.35s)+abort' --header 'Press CTRL-Y to copy command into clipboard'"

NOTE however I had this weird issue where I need to sleep after the xclip pipe, or otherwise the clipboard is not populated due to the abort :/
I tried different times, and anything below 0.35s fails (e.g. with sleep 0.3s it doesn't work). Which is quite a delay and a tiny bit annoying, but that's a workaround for now...
Any ideas on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olethanh picture olethanh  路  3Comments

ahmedelgabri picture ahmedelgabri  路  3Comments

nordlow picture nordlow  路  3Comments

natemara picture natemara  路  3Comments

lbeier picture lbeier  路  3Comments