Skip to content

Instantly share code, notes, and snippets.

@allen-ball
Last active February 8, 2022 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allen-ball/fdc974e6e24e391ddcfad3d61b9a5230 to your computer and use it in GitHub Desktop.
Save allen-ball/fdc974e6e24e391ddcfad3d61b9a5230 to your computer and use it in GitHub Desktop.
`.grip/settings.py` for https://github.com/joeyespo/grip that populates USERNAME and PASSWORD from invoking `git credential fill` with I/O through a pipe. See https://blog.hcf.dev/article/2021-07-27-grip.
# .grip/settings.py
# Uses "git credential fill" to populate USERNAME and PASSWORD
def git_credential_fill():
import subprocess
argv = ["git", "credential", "fill"]
process = subprocess.Popen(argv, text = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
output = process.communicate(input = "protocol=https\nhost=github.com\n")[0].strip()
map = dict(item.split("=") for item in output.splitlines())
return (map["username"], map["password"])
(USERNAME, PASSWORD) = git_credential_fill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment