summaryrefslogtreecommitdiff
path: root/stdin-wrapper
diff options
context:
space:
mode:
authorƁukasz Jan Niemier <lukasz@niemier.pl>2016-10-22 14:52:49 +0200
committerw0rp <w0rp@users.noreply.github.com>2016-10-22 13:52:49 +0100
commite293e0b5abd182ec006e49ef975fc648797444ba (patch)
tree901fde7da350ecf73150017f080af2b3af6d5b7b /stdin-wrapper
parent216eadbcbead15613e1725aa023bbcfd014b7573 (diff)
downloadale-e293e0b5abd182ec006e49ef975fc648797444ba.zip
Use `cat` instead of `read -r` to stream stdin to file (#120)
* Use `cat` instead of `read -r` to stream stdin to file * Cleanup dmd-wrapper * Fix typo * Make wrapper work on macOS * Use fifo instead of temporary file * Fix stdin-wrapper * Use `awk` instead of `read` hackery * Finish refactoring * Fix `exec` issue * Add myself as an coauthor of wrapper scripts (no shame at all :P) * Fix dmd-wrapper * Extract check_dubfile
Diffstat (limited to 'stdin-wrapper')
-rwxr-xr-xstdin-wrapper20
1 files changed, 14 insertions, 6 deletions
diff --git a/stdin-wrapper b/stdin-wrapper
index c1758df0..492035e1 100755
--- a/stdin-wrapper
+++ b/stdin-wrapper
@@ -1,20 +1,28 @@
#!/usr/bin/env bash
-# Author: w0rp <devw0rp@gmail.com>
+# Authors: w0rp <devw0rp@gmail.com>, hauleth <lukasz@niemier.pl>
# Description: This script implements a wrapper for any program which does not accept
# stdin input on most Unix machines. The input to the script is read to a
# temporary file, and the first argument sets a particular file extension
# for the temporary file.
+set -eu
+
# All of the following arguments are read as command to run.
file_extension="$1"
shift
-temp_file=$(mktemp --tmpdir "ale-XXXXXXXXX$file_extension")
-trap 'rm $temp_file' EXIT
+temp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'ale_linter')
+temp_file="$temp_dir/file$file_extension"
+trap 'rm -r "$temp_dir"' EXIT
-while read -r; do
- echo "$REPLY" >> "$temp_file"
-done
+# In perfect world it wouldn't be needed, but some tools (`go vet`, I am looking
+# at you) do not fit in line and require filename ending. Otherwise it would be
+# simple as
+#
+# "$@" /dev/stdin
+#
+# without all that hackery with copying `/dev/stdin`
+cp /dev/stdin "$temp_file"
"$@" "$temp_file"