Last active
June 24, 2020 08:14
-
-
Save thydel/524e88147a65f3bff526a86aa5227621 to your computer and use it in GitHub Desktop.
gist helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/make -f | |
make := $(lastword $(MAKEFILE_LIST)) | |
$(make): pass-dummy; | |
SHELL := bash | |
.DEFAULT_GOAL := main | |
main:; @date | |
#### | |
github := https://api.github.com | |
users := thydel thyepi | |
user ?= thydel | |
. := $(or $(filter $(user),$(users)),$(error $(user) not in $(users))) | |
export user | |
#### | |
ssh-config-github := Use multiple github accounts | |
gist-helper.mk := gist helper | |
github-helper.mk := github helper | |
infra-gitignore.txt := gitignore skeleton for typical infra playbook | |
new := ssh-config-github gist-helper.mk github-helper.mk infra-gitignore.txt | |
#### | |
help := | |
# Ensure we won't block on pass because gpg-agent absent or key not in | |
# cache | |
gpg-agent-info-export = < ~/.gpg-agent-info xargs -i echo export {} | |
gpg-agent-info-export:; @echo 'source <($(gpg-agent-info-export))' | |
help += gpg-agent-info-export | |
check-pass := timeout 1 pass dummy < /dev/null > /dev/null | |
check-pass:; @echo '$(check-pass)' | |
help += check-pass | |
$(eval $(shell $(gpg-agent-info-export))) | |
pass-dummy:; @$(check-pass) | |
.PHONY: pass-dummy | |
# Ensure we won't fail because my agent reach his maximum lifetime | |
$(if $(filter $(shell ssh-add -l > /dev/null || echo T),T),$(error your agent has no keys)) | |
#### | |
list.jq := .[] | .id, .description, (.files | keys | @csv) | |
list.curl := curl -s $(github)/users/$(user)/gists | |
list.fmt := paste -d: - - - | column -ts: | |
list := $(list.curl) | jq -r '$(list.jq)' | $(list.fmt) | |
list:; $($@) | |
check.jq = .[] | [select(.description == "$1")] | $(list.jq) | |
check = $(list.curl) | jq -r '$(call check.jq,$1)' | $(list.fmt) | |
check/%:; $(call check,$($*)) | |
$(new:%=check/%): | |
#### | |
import.jq := def file: (.files | keys[0]); | |
import.jq += (.[] | file + ".id := " + .id, file + ".desc := " + .description), | |
import.jq += "gists := " + ([.[]|file + " "] | add) | |
gists.mk := @echo | |
gists.mk := $(list.curl) | jq -r '$(import.jq)' | |
tmp/gists.mk: $(make) tmp/.stone .stone; @$($(@F)) > $@ | |
import: tmp/gists.mk | |
include tmp/gists.mk | |
show = $(foreach gist,$(gists),echo $($(gist).id) $(gist) $($(gist).desc);) | |
show: import; @$($@) | |
#### | |
%/.stone:; mkdir -p $(@D); touch $@ | |
.stone:; touch $@ | |
stone:; touch .$@ | |
.PHONY: stone | |
#### | |
mygist.head := \#!/usr/bin/make -f\n | |
mygist.head += \# Generated from https://gist.github.com/thydel/524e88147a65f3bff526a86aa5227621\n | |
mygist.head += \n | |
mygist.head += make := $$(lastword $$(MAKEFILE_LIST))\n | |
mygist.head += SHELL := bash\n | |
mygist.head += .DEFAULT_GOAL := show\n | |
mygist.head += \n | |
mygist.head += users := thydel thyepi\n | |
mygist.head += user ?= thydel\n | |
mygist.head += . := $$(or $$(filter $$(user),$$(users)),$$(error $$(user) not in $$(users)))\n | |
mygist.head += \n | |
mygist.head += clone = git clone git@$$(user).gist.github.com:$$(or $$($$*.id),$$(error $$* undefined)).git $$(basename $$*)\n | |
mygist.head += gist := https://gist.githubusercontent.com\n | |
mygist.head += fetch = curl -s $$(gist)/$$(user)/$$($$*.id)/raw > $$*; chmod +x $$*;\n | |
mygist.head += show = $$(foreach gist,$$(gists),echo $$($$(gist).id) $$(gist) $$($$(gist).desc);)\n | |
mygist.head += clone/% fetch/%:; $$($$(@D))\n | |
mygist.head += show:; @$$($$@)\n | |
mygist := ( | |
mygist += echo -e '$(mygist.head)' | sed -e '/^ /s///'; | |
mygist += cat tmp/gists.mk; | |
mygist += ) | |
tmp/mygist: $(make) import; @$($(@F)) > $@; chmod +x $@ | |
mygist: tmp/mygist | |
.PHONY: mygist | |
#### | |
clone = git clone git@$(user).gist.github.com:$(or $($*.id),$(error $* undefined)).git $(basename $*) | |
gist := https://gist.githubusercontent.com | |
fetch = curl -s $(gist)/$(user)/$($*.id)/raw > $*; chmod +x $*; | |
clone/% fetch/%:; $($(@D)) | |
#### | |
define create.jq | |
{ | |
description: "$(or $($1),$(error unknown $1))", | |
public: true, | |
files: { | |
"$1": { | |
content: "Dummy" | |
} | |
} | |
} | |
endef | |
define create | |
( | |
p=$$(pass github/$(user)); | |
jq -n '$(strip $(call create.jq,$1))' | |
| curl -s -u $(user):$$p $(github)/gists -d @- | |
) | |
endef | |
create.dep = $(list.curl) | jq -e -r '$(call check.jq,$1)' | |
create/%:; @$(call create.dep,$($*)) > /dev/null || $(strip $(call create,$*)) | |
$(new:%=create/%): | |
#### | |
define lines | |
echo 'echo $$PATH | grep ":\.:*" | line > /dev/null || export PATH=$$PATH:.'; | |
echo 'export GIT_PAGER=cat'; | |
echo "export GIT_EDITOR='emacsclient -s epi -c'"; | |
echo "export GIT_EDITOR='emacsclient -s thy -c'"; | |
echo 'git config push.default simple'; | |
echo 'git config user.email [email protected]'; | |
echo 'git config user.email [email protected]'; | |
echo 'git config tag.sort version:refname'; | |
echo 'echo '*~' >> .gitignore'; | |
echo 'echo '*~' >> .git/info/exclude'; | |
echo 'echo 'tmp/' >> .git/info/exclude'; | |
echo 'echo '.stone' >> .git/info/exclude'; | |
echo 'env DISPLAY=:0.0 git rebase -i HEAD~2'; | |
echo "git commit -m 'Makes firts commit'"; | |
echo "git status"; | |
echo "git diff"; | |
echo "git add . -n"; | |
echo "git log --oneline"; | |
endef | |
help += lines | |
lines:; @$(strip $($@)) | |
#### | |
help: $(help); | |
.PHONY: help $(help) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a good gist