You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
926 B
Bash

4 years ago
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2019-12-20 16:01:28 +0000 (Fri, 20 Dec 2019)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback
#
# https://www.linkedin.com/in/harisekhon
#
4 years ago
# Helper script for calling from vim function to run programs or execute with args extraction
#
# Runs the value of the 'run:' header from the given file
4 years ago
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
4 years ago
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4 years ago
# # run: <output this bit>
# // run: <output this bit>
4 years ago
run_cmd="$(perl -ne 'if(/^\s*(#|\/\/)\s*run:/){s/^\s*(#|\/\/)\s*run:\s*//; print $_; exit}' "$1")"
if [ -n "$run_cmd" ]; then
cd "$(dirname "$1")"
eval "$run_cmd"
else
eval "$1" "$("$srcdir/args_extract.sh" "$1")"
fi