Skip to content

Commit

Permalink
fix: allow printing compact runfile
Browse files Browse the repository at this point in the history
  • Loading branch information
evnp committed Sep 5, 2024
1 parent 2bab52f commit 97d5d4c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions runfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

# run :: v0.0.1

function compact-file() {
sed -e '/^$/d' -e 's/^[[:space:]]//'
}

function optionally-compact-file() {
[[ " $* " == *' --compact '* ]] && compact-file || cat
}

function create-runfile() { local buffer=''
if [[ " $* " != *' --overwrite-runfile '* ]] && [[ -e 'Runfile' ]]
then
Expand All @@ -10,7 +18,7 @@ function create-runfile() { local buffer=''
exit 1
fi

buffer="$( cat <<EOF
optionally-compact-file "$@" <<EOF > Runfile
s start: stop # start app
run build env=dev # tasks can be run directly from other tasks
echo "starting app"
Expand All @@ -21,20 +29,13 @@ stop: # stop app
b build: lint # build app for environment [vars: env]
[[ -n \$(env) ]] && echo "buiding app for \$(env)" || echo "error: missing env"
t test: build # run all tests or specific tests [vars: name1, name2, etc.]
t test: # run all tests or specific tests [vars: name1, name2, etc.]
run build env=test
[[ -n \$(@) ]] && echo "running tests \$(@)" || echo "running all tests"
l lint: # lint all files or specific file [vars: file]
[[ -n \$(1) ]] && echo "linting file \$(1)" || echo "linting all files"
EOF
)"

if [[ " $* " == *' --compact '* ]]
then
echo "${buffer}" | sed -e '/^$/d' -e 's/^\t//' > Runfile
else
echo "${buffer}" > Runfile
fi
}

function lowercase-file() {
Expand Down Expand Up @@ -67,7 +68,7 @@ function edit-file-smartcase() { local name=''
}

function print-file-smartcase() {
cat "$( smartcase-file "$1" )"
cat "$( smartcase-file "$1" )" | optionally-compact-file "$@"
}

function print-makefile() {
Expand Down Expand Up @@ -103,7 +104,7 @@ function main() ( set -euo pipefail
[[ " $* " == *' --create-runfile '* || " $* " == *' --overwrite-runfile '* ]] && \
create-runfile "$@" && edit-file-smartcase runfile --confirm "$@" && exit 0
[[ " $* " == *' --print-runfile '* ]] && \
cd-to-nearest-file runfile && print-file-smartcase runfile && exit 0
cd-to-nearest-file runfile && print-file-smartcase runfile "$@" && exit 0
[[ " $* " == *' --edit-runfile '* ]] && \
cd-to-nearest-file runfile && edit-file-smartcase runfile "$@" && exit 0
[[ " $* " == *' --edit-makefile '* ]] && \
Expand Down

0 comments on commit 97d5d4c

Please sign in to comment.