diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-03-17 15:05:49 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-03-17 15:36:21 -0600 |
| commit | ca6b10ffb7795fd3431a55b9c546f6b127ac04a5 (patch) | |
| tree | 2597b790d958f42659e06a5961053929f80f388d /pkgs/scripts/clip.nix | |
| parent | 82c53e2c5c23ccd4fb2c24511084f7a828a20731 (diff) | |
pkgs: add clip
Diffstat (limited to '')
| -rw-r--r-- | pkgs/scripts/clip.nix | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pkgs/scripts/clip.nix b/pkgs/scripts/clip.nix new file mode 100644 index 0000000..862d82e --- /dev/null +++ b/pkgs/scripts/clip.nix @@ -0,0 +1,35 @@ +{ lib ,writeShellScriptBin, gnome, 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.gnome-screenshot}/bin/gnome-screenshot "$OPTIONS" -f "$CLIP" + ${copyOut} + + rm "$CLIP" +'' |
