Last active
April 25, 2024 09:40
-
-
Save christian-korneck/3e181b7bb043e7be24c73939dd7ea2a6 to your computer and use it in GitHub Desktop.
octokey (.bashrc)
This file contains 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
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