Getting GPG info from `gh` & GitHub

Open
#9 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
github, shell
Domain
cli, security, tooling

Research direction

Start with the supplied shell snippet, focusing on gh auth status, ~/.config/gh/hosts.yml, GitHub's .gpg endpoint, and the GPG fingerprint command. The issue does not name a repository file or test; completion should make the intended GitHub user and GPG fingerprint retrieval work within the project's setup flow.

Written by the indexing model from the issue text.

Description

@namcios,

You might find these code snippets useful:

#!/bin/bash

if [[ $(command -v gh) == "" ]]; then

    printf "No \`gh\` Installed!\n"
    brew install gh
    printf "Installed \`gh\`.\n"
fi

if !(gh auth status --hostname "github.com" > /dev/null 2>&1); then
    printf "You are not logged into \`gh\`!\n"
    printf "Authenticate gh with GitHub using the Web and set ssh as default.\n"
    gh auth login
    printf "Logged into GitHub.\n"
fi


# Get the GitHub User Name from GitHub's `gh` cli config files
My_GitHub_User=$(cat <~/.config/gh/hosts.yml | grep -A0 user: | cut -d: -f2 | tr -d ' "')

printf "My_GitHub_User:\t$My_GitHub_User\t✅\n"

## Setup gnupg

## install gnupg if it is not already instealled
if [[ $(command -v gpg) == "" ]]; then
    printf "No GPG Installed!\n"
    brew install gpg2 pinentry-mac
    printf "Installing gpg & pinentry-mac\n"
fi


My_GPG_Key=$(curl https://github.com/$My_GitHub_User.gpg 2>/dev/null)
  if [ -z "$My_GPG_Key" ] ; then
    script_exit "ERROR: Unable to find $My_GPG_Key from https://github.com/$My_GitHub_User.gpg!\n" 1
  else
    printf "My_GPG_Key:\tRETREIVED\t✅\n"
  fi

export GPG_KEY=$My_GPG_Key

## Get GPG Fingerprint from $My_GPG_Key
# For instance https://github.com/ChristopherA.gpg
# $My_GPG_Key would equal "FDFE14A54ECB30FC5D2274EFF8D36C91357405ED"


My_GPG_KEY_Fingerprint=`echo $My_GPG_Key 2>/dev/null | gpg --with-colons --import-options show-only --import --fingerprint 2>/dev/null | awk -F: '$1 == "fpr" {print $10}' | head -1`

printf "My_GPG_KEY_Fingerprint:\t$My_GPG_Key_Fingerprint\t✅\n"
Dominant language
Shell
Stars
8
Forks
5
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Shell/Bash issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.