Skip to content

Feature: Built-in copy action for cross-platform clipboard support #4820

Description

@LangLangBart

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.73.1 (ae78a5c)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

Issue: often used snippet, but macOS only; will fail when using same setup on a non-mac

fzf --bind 'enter:execute:echo -n {1} | pbcopy'

Solution: OS-independent way to copy a string to clipboard

fzf --bind 'enter:copy-string:{1}'

a paste action seems redundant, user already has ⌃ ControlV / ⌘ CommandV

one possible use case was accessing the clipboard value, e.g. through a placeholder (not important)

# popup that disappears after 2s; modified example from CHANGELOG.md 0.63.0
echo "https://example.com" | fzf \
  --bind "ctrl-y:copy-string:{}" \
  --bind "ctrl-y:+change-footer:{input_paste}" \
  --bind "ctrl-y:+bg-cancel+bg-transform-footer:sleep 2"

tools with clipboard feature

broot (rust)

name key description
copy_line alt-c copy selected line (in tree or preview)
copy_path copy path to system clipboard
input_paste ctrl-v paste the clipboard content into the input
# needs to be built with feature flag (brew formula does not set it)
cargo install broot --features clipboard
# run
~/.cargo/bin/broot
# press 'alt-c' on selected item
# press 'ctrl-v' to paste

television (rust)

handles it without a dedicated crate

name key
copy_entry_to_clipboard ctrl-y

additional notes

some terminals support OSC 52 (ghostty, VSCode 1.91+, ...)

printf "\033]52;c;%s\007" "$(printf "FooBar" | base64)"

related issues

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions