Skip to content

Commit 97d5d4c

Browse files
committed
fix: allow printing compact runfile
1 parent 2bab52f commit 97d5d4c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

runfile.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
# run :: v0.0.1
44

5+
function compact-file() {
6+
sed -e '/^$/d' -e 's/^[[:space:]]//'
7+
}
8+
9+
function optionally-compact-file() {
10+
[[ " $* " == *' --compact '* ]] && compact-file || cat
11+
}
12+
513
function create-runfile() { local buffer=''
614
if [[ " $* " != *' --overwrite-runfile '* ]] && [[ -e 'Runfile' ]]
715
then
@@ -10,7 +18,7 @@ function create-runfile() { local buffer=''
1018
exit 1
1119
fi
1220

13-
buffer="$( cat <<EOF
21+
optionally-compact-file "$@" <<EOF > Runfile
1422
s start: stop # start app
1523
run build env=dev # tasks can be run directly from other tasks
1624
echo "starting app"
@@ -21,20 +29,13 @@ stop: # stop app
2129
b build: lint # build app for environment [vars: env]
2230
[[ -n \$(env) ]] && echo "buiding app for \$(env)" || echo "error: missing env"
2331
24-
t test: build # run all tests or specific tests [vars: name1, name2, etc.]
32+
t test: # run all tests or specific tests [vars: name1, name2, etc.]
33+
run build env=test
2534
[[ -n \$(@) ]] && echo "running tests \$(@)" || echo "running all tests"
2635
2736
l lint: # lint all files or specific file [vars: file]
2837
[[ -n \$(1) ]] && echo "linting file \$(1)" || echo "linting all files"
2938
EOF
30-
)"
31-
32-
if [[ " $* " == *' --compact '* ]]
33-
then
34-
echo "${buffer}" | sed -e '/^$/d' -e 's/^\t//' > Runfile
35-
else
36-
echo "${buffer}" > Runfile
37-
fi
3839
}
3940

4041
function lowercase-file() {
@@ -67,7 +68,7 @@ function edit-file-smartcase() { local name=''
6768
}
6869

6970
function print-file-smartcase() {
70-
cat "$( smartcase-file "$1" )"
71+
cat "$( smartcase-file "$1" )" | optionally-compact-file "$@"
7172
}
7273

7374
function print-makefile() {
@@ -103,7 +104,7 @@ function main() ( set -euo pipefail
103104
[[ " $* " == *' --create-runfile '* || " $* " == *' --overwrite-runfile '* ]] && \
104105
create-runfile "$@" && edit-file-smartcase runfile --confirm "$@" && exit 0
105106
[[ " $* " == *' --print-runfile '* ]] && \
106-
cd-to-nearest-file runfile && print-file-smartcase runfile && exit 0
107+
cd-to-nearest-file runfile && print-file-smartcase runfile "$@" && exit 0
107108
[[ " $* " == *' --edit-runfile '* ]] && \
108109
cd-to-nearest-file runfile && edit-file-smartcase runfile "$@" && exit 0
109110
[[ " $* " == *' --edit-makefile '* ]] && \

0 commit comments

Comments
 (0)