From 3614df7450860858f05a1eefe34c7c9c1f9261f1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 15 Jun 2019 13:52:32 -0700 Subject: More robust/automatic handling of PICKER --- Makefile | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5c06cc5..3902c84 100644 --- a/Makefile +++ b/Makefile @@ -8,23 +8,34 @@ CWARN=-Wall -Wpedantic -Wno-unknown-pragmas G= ifeq ($(shell uname),Darwin) -CFLAGS += -D_DARWIN_C_SOURCE -CWARN += -Weverything -Wno-missing-field-initializers -Wno-padded\ - -Wno-missing-noreturn -Wno-cast-qual + CFLAGS += -D_DARWIN_C_SOURCE + CWARN += -Weverything -Wno-missing-field-initializers -Wno-padded\ + -Wno-missing-noreturn -Wno-cast-qual endif -ifeq ($(PICKER),fzy) -CFLAGS += -D'PICK(prompt, initial)=" { printf \"\\033[3A\" >/dev/tty; fzy --lines=3 --prompt=\"" prompt "\" --query=\"" initial "\"; } "' +PICKER_FLAG= +ifeq (, $(PICKER)) + PICKER=$(shell sh -c "(which fzy >/dev/null 2>/dev/null && echo 'fzy') || (which fzf >/dev/null 2>/dev/null && echo 'fzf') || (which pick >/dev/null 2>/dev/null && echo 'pick') || (which ask >/dev/null 2>/dev/null && echo 'ask')") endif -ifeq ($(PICKER),fzf) -CFLAGS += -D'PICK(prompt, initial)=" { printf \"\\033[3A\" >/dev/tty; fzf --height=4 --prompt=\"" prompt "\" --query=\"" initial "\"; } "' +ifneq (, $(PICKER)) + PICKER_FLAG=-D"PICK(prompt, initial)=\"$(PICKER)\"" endif -ifeq ($(PICKER),ask) -CFLAGS += -D'PICK(prompt, initial)=" ask --prompt=\"" prompt "\" --query=\"" initial "\" "' +ifeq ($(shell which $(PICKER)),$(shell which fzy || echo '')) + PICKER_FLAG=-D'PICK(prompt, initial)="{ printf \"\\033[3A\" >/dev/tty; fzy --lines=3 --prompt=\"" prompt "\" --query=\"" initial "\"; }"' endif +ifeq ($(shell which $(PICKER)),$(shell which fzf || echo '')) + PICKER_FLAG=-D'PICK(prompt, initial)="{ printf \"\\033[3A\" >/dev/tty; fzf --height=4 --prompt=\"" prompt "\" --query=\"" initial "\"; }"' +endif +ifeq ($(shell which $(PICKER)),$(shell which ask || echo '')) + PICKER_FLAG=-D'PICK(prompt, initial)="ask --prompt=\"" prompt "\" --query=\"" initial "\""' +endif +ifeq ($(shell which $(PICKER)),$(shell which pick || echo '')) + PICKER_FLAG=-D'PICK(prompt, initial)="pick -q \"" initial "\""' +endif +CFLAGS += $(PICKER_FLAG) ifneq (, $(USE_ASK)) -CFLAGS += -D'USE_ASK=1' + CFLAGS += -D'USE_ASK=1' endif all: $(NAME) -- cgit v1.2.3