summaryrefslogtreecommitdiffstats
path: root/.config/nnn/plugins/joe_clipper
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2025-09-08 21:29:37 +0200
committerJoe <rbo@gmx.us>2025-09-08 21:29:37 +0200
commitaccfed3e8994784fbe0381da0d6b0a18a26c59f1 (patch)
tree0819b013fbca68dc0fbdb922daef34b57b9da05f /.config/nnn/plugins/joe_clipper
parentfuck my preview (diff)
downloaddotfiles-bsd-accfed3e8994784fbe0381da0d6b0a18a26c59f1.tar.gz
dotfiles-bsd-accfed3e8994784fbe0381da0d6b0a18a26c59f1.tar.bz2
dotfiles-bsd-accfed3e8994784fbe0381da0d6b0a18a26c59f1.tar.xz
dotfiles-bsd-accfed3e8994784fbe0381da0d6b0a18a26c59f1.tar.zst
dotfiles-bsd-accfed3e8994784fbe0381da0d6b0a18a26c59f1.zip
up
Diffstat (limited to '.config/nnn/plugins/joe_clipper')
-rwxr-xr-x.config/nnn/plugins/joe_clipper76
1 files changed, 76 insertions, 0 deletions
diff --git a/.config/nnn/plugins/joe_clipper b/.config/nnn/plugins/joe_clipper
new file mode 100755
index 0000000..8c0fa5d
--- /dev/null
+++ b/.config/nnn/plugins/joe_clipper
@@ -0,0 +1,76 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Cwd qw(cwd);
+
+sub close_io
+{
+ open STDIN, '<', '/dev/null' or die $!;
+ open STDOUT, '>', '/dev/null' or die $!;
+ open STDERR, '>', '/dev/null' or die $!;
+ return;
+}
+
+sub clip_img
+{
+ my ($file) = @_;
+ my $pid;
+
+ $pid = fork();
+ if ($pid == 0) {
+ system("magick $file png:- | xclip -selection clipboard -t image/png");
+ exec(
+ 'notify-send',
+ '-t', '2000',
+ 'clipped image',
+ ' clipped image'
+ );
+ }
+ return;
+}
+
+sub clip_raw
+{
+ my ($file) = @_;
+
+ my $pid;
+
+ $pid = fork();
+ if ($pid == 0) {
+ system( "xclip -selection clipboard $file");
+ exec(
+ 'notify-send',
+ '-t', '2000',
+ 'clipped file',
+ ' clipped file'
+ );
+ }
+ return;
+}
+
+sub clip
+{
+ my ($file, $mimetype) = @_;
+
+ return clip_img($file) if $mimetype =~ /^image\//;
+ clip_raw($file);
+ return;
+}
+
+sub joe_clipper
+{
+ my $file = cwd() . '/' . $ARGV[0];
+ my $mimetype;
+
+ if (-d $file) {
+ return;
+ }
+ $mimetype=`file -bL --mime-type -- "$file"`;
+ clip($file, $mimetype);
+ return;
+}
+
+joe_clipper();
+
+__END__