From 53007b51f7e17f4e748d71620e533c754750eefe Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 9 Jul 2025 22:55:07 +0200 Subject: [PATCH] pbfile plugin Copies files to the macOS pasteboard for pasting with Cmd+V in Finder, messengers, and other apps. --- plugins/pbfile/README.md | 20 ++++++++++++++++++++ plugins/pbfile/pbfile.plugin.zsh | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 plugins/pbfile/README.md create mode 100644 plugins/pbfile/pbfile.plugin.zsh diff --git a/plugins/pbfile/README.md b/plugins/pbfile/README.md new file mode 100644 index 000000000..f9795947f --- /dev/null +++ b/plugins/pbfile/README.md @@ -0,0 +1,20 @@ +# pbfile plugin + +Copies files to the macOS pasteboard for pasting with Cmd+V in Finder, messengers, and other apps. + +To use it, add `pbfile` to the plugins array in your zshrc file: + +```zsh +plugins=(... pbfile) +``` + +## Usage + +- `pbfile `: copies the given file to the pasteboard for pasting as an attachment. + +## Examples + +```zsh +pbfile document.pdf +pbfile config.json +``` diff --git a/plugins/pbfile/pbfile.plugin.zsh b/plugins/pbfile/pbfile.plugin.zsh new file mode 100644 index 000000000..6780233b3 --- /dev/null +++ b/plugins/pbfile/pbfile.plugin.zsh @@ -0,0 +1,19 @@ +# Check if running on macOS +if [[ "$OSTYPE" != darwin* ]]; then + return +fi + +function pbfile() { + if [[ $# -ne 1 ]]; then + echo "Usage: pbfile " + return 1 + fi + + if [[ ! -e "$1" ]]; then + echo "File not found: $1" + return 1 + fi + + osascript -e "tell application \"Finder\" to set the clipboard to (POSIX file \"$(realpath "$1")\")" + echo "Copied $1 to pasteboard" +}