This repository has no description
612 B
27 lines
1{ nsxiv, writers }:
2
3writers.writeDashBin "sxiv" ''
4 set -efu
5 tmpfile="''${TMPDIR:-/tmp}/nsxiv_pipe_$$"
6 trap 'rm -f -- $tmpfile' EXIT
7
8 if [ "$#" -eq 0 ]; then
9 if [ -t 0 ]; then
10 echo "sxiv: No arguments provided" >&2; exit 1
11 else
12 # Consume stdin and put it in the temporal file
13 cat > "$tmpfile"
14 fi
15 fi
16
17 for arg in "$@"; do
18 # if it's a pipe then drain it to $tmpfile
19 [ -p "$arg" ] && cat "$arg" > "$tmpfile"
20 done
21
22 if [ -s "$tmpfile" ]; then
23 ${nsxiv}/bin/nsxiv -q "$@" "$tmpfile" # -q to silence warnings
24 else
25 ${nsxiv}/bin/nsxiv "$@" # fallback
26 fi
27''