Skip to content

Instantly share code, notes, and snippets.

@abn
Last active August 7, 2017 11:12
Show Gist options
  • Save abn/f6efd4ce3b899e1096912ca2a8278cff to your computer and use it in GitHub Desktop.
Save abn/f6efd4ce3b899e1096912ca2a8278cff to your computer and use it in GitHub Desktop.
Makefile snippet: json -> shell env var
# delete a line in an environment file that sets a var
# env_del(var,file)
define env_del
@{ [[ ! -e "$(2)" ]] || sed -i /'$(1)='/d $(2); } || :
endef
# given a env var name and json file, minify and add to specified file
# env_minify_json(var, json, dest)
define env_minify_json
$(call env_del,$(1),$(3))
@echo "$(1)=$$(jq -c . < $(2))" >> $(3)
endef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment