summaryrefslogtreecommitdiff
path: root/stdin-wrapper
blob: f81f4617e3eec16ce3eb9331973c47cf0a2e2de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash

# 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_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

"$@" "$temp_file"