@@ 19,23 19,18 @@ main() (
# ex: "foo.sh" to "/home/samsepi0l/foo.sh"
filepath=$(readlink -f -- "${file}")
- # Grab the resulting directory
- # ex: "/home/samsepi0l/foo.sh" to "/home/samsepi0l"
- filedir=$(dirname -- "${filepath}")
-
- # Create remote directory
- incus exec "${container_name}" -- mkdir -p "${filedir}"
-
- # Copy file over
- incus file push -q "${filepath}" "${container_name}${filepath}"
-
- # Lint
set +e
- incus exec "${container_name}" -- sh -c "shellcheck -f gcc ${filepath}"
+ output=$(incus exec "${container_name}" -- sh -c "shellcheck -f gcc -" < "${filepath}")
set -e
- # Cleanup
- incus exec "${container_name}" -- sh -c "rm -fr ${filedir}"
+ # Replace "-" with the actual filepath of the file.
+ # Shellcheck returns it as "-" since it validated from stdin, but in the
+ # error message, we need it to be the filepath so that vim can jump to
+ # the proper error location in the file.
+ #
+ # Note: not using `sed` here because the variable could inevitably contain
+ # the chosen sed delimiter.
+ echo "${output}" | awk '{sub(/^-:/, "'"${filepath}"':"); print}'
)