install.zsh: allow alternatives in deps
Specify a dependency as a|b to check if either a or b is available as a command. The script itself must check at runtime, which one is actually available and use the right one. Helper methods for this are provided in lib/common.zsh: - `alternatives a b` aliases a to b, if a is not available - `alternatives-noparam a b` replaces a with b, if a is not available, and discards any parameters (e.g. for replacing a formatter with cat)
This commit is contained in:
parent
0ca3e95262
commit
7c14c8ae1a
2 changed files with 17 additions and 8 deletions
|
@ -26,6 +26,14 @@ exists() {
|
|||
type "$1" &>/dev/null
|
||||
}
|
||||
|
||||
alternative() {
|
||||
if ! exists $1; then eval "$1(){ $2 \$@}"; fi
|
||||
}
|
||||
|
||||
alternative-noparam() {
|
||||
if ! exists $1; then eval "$1(){ $2 }"; fi
|
||||
}
|
||||
|
||||
depend() {
|
||||
local missing
|
||||
local i
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue