Skip to content

Instantly share code, notes, and snippets.

@christian-korneck
Last active April 25, 2024 09:40
Show Gist options
  • Save christian-korneck/3e181b7bb043e7be24c73939dd7ea2a6 to your computer and use it in GitHub Desktop.
Save christian-korneck/3e181b7bb043e7be24c73939dd7ea2a6 to your computer and use it in GitHub Desktop.
octokey (.bashrc)
function octokey () {
if [ "${1}" == "" ]; then echo -e "Get a github user's ssh key(s). \nUsage: octokey github_username [all | key_index]" && return 1; fi
case "${2}" in
"")
local key_index=0
;;
a)
local key_index='' #jq wildcard
;;
all)
local key_index=''
;;
*)
local key_index=${2} #user-specified entry
esac
local out=$(curl --fail -s https://api.github.com/users/${1}/keys | jq -r ".[$key_index].key")
if [ "$out" == "" ] || [ "$out" == "null" ]; then >&2 echo "error" && return 1; fi
echo "$out"
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment