summaryrefslogtreecommitdiffstats
path: root/lass/5pkgs/sxiv/default.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2022-12-12 19:44:00 +0100
committermakefu <github@syntax-fehler.de>2022-12-12 19:44:00 +0100
commit6eb5e44b7e5bdc8b1b3b5ffe40c146841f7afd10 (patch)
treef706bf7c3c7a289f680ac329caa2b578e5145a56 /lass/5pkgs/sxiv/default.nix
parent96e934dc8a353cff91ef824f6a125ed49996d058 (diff)
parent3884243448869bdf09f6434b385e532c7c26ae88 (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass/5pkgs/sxiv/default.nix')
-rw-r--r--lass/5pkgs/sxiv/default.nix27
1 files changed, 27 insertions, 0 deletions
diff --git a/lass/5pkgs/sxiv/default.nix b/lass/5pkgs/sxiv/default.nix
new file mode 100644
index 00000000..04fc1c3f
--- /dev/null
+++ b/lass/5pkgs/sxiv/default.nix
@@ -0,0 +1,27 @@
+{ nsxiv, writers }:
+
+writers.writeDashBin "sxiv" ''
+ set -efu
+ tmpfile="''${TMPDIR:-/tmp}/nsxiv_pipe_$$"
+ trap 'rm -f -- $tmpfile' EXIT
+
+ if [ "$#" -eq 0 ]; then
+ if [ -t 0 ]; then
+ echo "sxiv: No arguments provided" >&2; exit 1
+ else
+ # Consume stdin and put it in the temporal file
+ cat > "$tmpfile"
+ fi
+ fi
+
+ for arg in "$@"; do
+ # if it's a pipe then drain it to $tmpfile
+ [ -p "$arg" ] && cat "$arg" > "$tmpfile"
+ done
+
+ if [ -s "$tmpfile" ]; then
+ ${nsxiv}/bin/nsxiv -q "$@" "$tmpfile" # -q to silence warnings
+ else
+ ${nsxiv}/bin/nsxiv "$@" # fallback
+ fi
+''