~chimo/dotfiles

221d4e877b15910a91d51a12df121b915ba4a816 — chimo 3 months ago a07dd7e
.local/bin/shellcheck: Use stdin instead of copying files over.
1 files changed, 9 insertions(+), 14 deletions(-)

M .local/bin/libs/shellcheck.sh
M .local/bin/libs/shellcheck.sh => .local/bin/libs/shellcheck.sh +9 -14
@@ 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}'
)