Skip to content

Commit

Permalink
Update fallback script to handle input on stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrenierejm committed Sep 7, 2023
1 parent f69ed58 commit 14d4854
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
gronWithFallback = pkgs.writeShellApplication {
name = "gron-with-fallback";
runtimeInputs = [ gron ];
text = ''
gron "$1" 2>/dev/null || cat "$1"
'';
text = pkgs.readFile ./gron-with-fallback.sh;
};
};

Expand Down
10 changes: 10 additions & 0 deletions gron-with-fallback.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

if [ "$#" -eq 0 ]; then
input_file="$(mktemp)"
cat - >"$input_file"
gron "$input_file" 2>/dev/null || cat "$input_file"
rm "$input_file"
else
gron "$1" 2>/dev/null || cat "$1"
fi

0 comments on commit 14d4854

Please sign in to comment.