From a06af824ee7d83054a4b34a8004283fbd05aca86 Mon Sep 17 00:00:00 2001 From: umaranis Date: Fri, 8 Sep 2023 05:39:06 +1000 Subject: [PATCH] plugins for integration with MacOS clipboard --- .circleci/config.yml | 2 +- plugins/README.md | 2 ++ plugins/cbcopy-mac | 16 ++++++++++++++++ plugins/cbpaste-mac | 24 ++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 plugins/cbcopy-mac create mode 100755 plugins/cbpaste-mac diff --git a/.circleci/config.yml b/.circleci/config.yml index 78ad187b..25628f47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,7 +66,7 @@ jobs: echo "########## clang-tidy-15 ##########" clang-tidy-15 src/* -- -I/usr/include -I/usr/include/ncursesw echo "########## shellcheck ##########" - find plugins/ -type f -not -name "*.md" -exec shellcheck {} + + find plugins/ -type f ! \( -name "*.md" -o -name "*-mac" \) -exec shellcheck {} + package-and-publish: machine: true diff --git a/plugins/README.md b/plugins/README.md index 167676a1..e20d1bb2 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -16,6 +16,8 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [autojump](autojump) | Navigate to dir/path | sh | [jump](https://github.com/gsamokovarov/jump)/autojump/
zoxide/z/[z.lua](https://github.com/skywind3000/z.lua) | | [boom](boom) | Play random music from dir | sh | [moc](http://moc.daper.net/) | | [bulknew](bulknew) | Create multiple files/dirs at once | bash | sed, xargs, mktemp | +| [cbcopy-mac](cbcopy-mac) | Copy the hovered file to MacOS clipboard | applescript | macos | +| [cbpaste-mac](cbpaste-mac) | Pastes files from MacOS clipboard into currect directory | macos | | [cdpath](cdpath) | `cd` to the directory from `CDPATH` | sh | fzf | | [chksum](chksum) | Create and verify checksums [✓] | sh | md5sum,
sha256sum | | [cmusq](cmusq) | Queue/play files/dirs in cmus player [✓] | sh | cmus, pgrep | diff --git a/plugins/cbcopy-mac b/plugins/cbcopy-mac new file mode 100755 index 00000000..a117a72f --- /dev/null +++ b/plugins/cbcopy-mac @@ -0,0 +1,16 @@ +#!/usr/bin/osascript + +# Description: Copy the hovered file to MacOS clipboard. +# +# Note: Supports only MacOS +# +# Shell: POSIX compliant +# Author: Syed Umar Anis + + +on run args + set filePath to (second item of args & "/" & first item of args) + tell application "Finder" + set the clipboard to (filePath as POSIX file) + end tell +end diff --git a/plugins/cbpaste-mac b/plugins/cbpaste-mac new file mode 100755 index 00000000..51af9e29 --- /dev/null +++ b/plugins/cbpaste-mac @@ -0,0 +1,24 @@ +#!/usr/bin/env sh +# shellcheck disable=all + +# Description: Paste the clipboard files into the current directory. +# Only works if clipboard contents are files. +# +# Note: Supports only MacOS +# +# Shell: POSIX compliant +# Author: Syed Umar Anis + + +fs=($( osascript -e "use framework \"Foundation\" + property this : a reference to the current application + property NSPasteboard : a reference to NSPasteboard of this + property NSURL : a reference to NSURL of this + property pb : a reference to NSPasteboard's generalPasteboard + + property text item delimiters : linefeed + + pb's readObjectsForClasses:[NSURL] options:[] + (result's valueForKey:\"path\") as list as text" )) + +cp -R "${fs[@]}" "$2/" \ No newline at end of file