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" +}