summaryrefslogtreecommitdiff
path: root/pkgs/scripts/clip.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/scripts/clip.nix')
-rw-r--r--pkgs/scripts/clip.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/pkgs/scripts/clip.nix b/pkgs/scripts/clip.nix
new file mode 100644
index 0000000..3e16e3e
--- /dev/null
+++ b/pkgs/scripts/clip.nix
@@ -0,0 +1,50 @@
+{
+ lib,
+ writeShellScriptBin,
+ gnome-screenshot,
+ xclip,
+ file,
+ imagemagick,
+ toPDF,
+ ...
+}:
+with lib; let
+ name =
+ if toPDF
+ then "clip-pdf"
+ else "clip";
+
+ pdfCmdline = optionalString toPDF ''
+ if [ $# -lt 1 ]; then
+ echo "Usage: $0 <out.pdf> [opts...]" >&2
+ exit 1
+ fi
+
+ OUT="$1"
+ shift
+ '';
+
+ copyOut =
+ if toPDF
+ then ''
+ ${imagemagick}/bin/convert "$CLIP" "$OUT"
+ ''
+ else ''
+ ${xclip}/bin/xclip -selection clipboard \
+ -t $(${file}/bin/file -b --mime-type $CLIP) <"$CLIP"
+ '';
+in
+ writeShellScriptBin name ''
+ ${pdfCmdline}
+
+ OPTIONS=-a
+ if [ "x$@" != "x" ]; then
+ OPTIONS="$@"
+ fi
+
+ CLIP="$HOME/vtmp/$$.png"
+ ${gnome-screenshot}/bin/gnome-screenshot "$OPTIONS" -f "$CLIP"
+ ${copyOut}
+
+ rm "$CLIP"
+ ''