diff options
author | Joe <rbo@gmx.us> | 2025-09-08 21:29:37 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2025-09-08 21:29:37 +0200 |
commit | accfed3e8994784fbe0381da0d6b0a18a26c59f1 (patch) | |
tree | 0819b013fbca68dc0fbdb922daef34b57b9da05f /.config/nnn/plugins/joe_clipper | |
parent | fuck my preview (diff) | |
download | dotfiles-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_clipper | 76 |
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__ |