Is it possible to provide a default if $*
is empty in a :make
?
I'd like to specify :makeprg
so that:
:make
runsswift build
:make foo bar
runsswift foo bar
.
This isn't really a vim answer, but consider having an actual makefile (or a shell script, but makefiles are beautiful for this kind of thing—see the language agnostic makefile and is it worth using make).
Then, you don't need weird workarounds for vim's $*
(I had to look it up to be sure of what you were talking about).
For example (pay attention to the tabs, which are showing as spaces, unfortunately):
all: build_output build_output: swift build foo_output: swift foo bar_output: swift bar
Then you can simply make
, make foo_output
, or make bar_output
, where
*_output
is a file or directory tree generated by swift *
.
Let make do its job. Don't beat it to death.
The equivalent shell script would have to be something like
#! /usr/bin/env bash
set -euo pipefail
usage() {
cat <<DOG
usage: $0 [args...]
DOG
}
die() {
local ex="${1:-1}"
exit "$ex"
}
usage_and_die() { usage && die; }
build() {
swift build
}
foo() {
swift foo
}
bar() {
swift bar
}
main() {
if (($# < 1)) ; then
build
else
for param;
case "$param" in
-h|--help) usage_and_die ;;
*) "$param" ;;
esac
done
fi
}
main "$@"
And the complexity of this beast will only grow. Just use make.
I suppose you could do something like
command -nargs=* Make if len(<q-args>) > 0 | make <q-args> | else | make build | endif
setlocal makeprg=swift
But then you have to use this new command, and maintain it, and all that garbage. Plus, if you have a workflow, why not encode that in your makefile, and let others benefit from seeing it?
swift build
, swift test
, etc. I want something that works for all projects. My default for SwiftPM projects is to run build, but I should be able to run the tests too.