Skip to content

Instantly share code, notes, and snippets.

@stephensabatini
Created January 28, 2022 02:35
Show Gist options
  • Save stephensabatini/24ee5a1aeebf95c50b43da4866d83411 to your computer and use it in GitHub Desktop.
Save stephensabatini/24ee5a1aeebf95c50b43da4866d83411 to your computer and use it in GitHub Desktop.
Macro for copying SSH key to clipboard and outputting to console for those who don't support pbcopy. Add to your .bashrc or .zshrc.
sshkey () {
local file="$HOME/.ssh/id_rsa.pub"
if [ -n "$file" ] ; then # If the file exists.
cat "$file"
if pbcopy < "$file" ; then # If the text successfully copied to the clipboard.
tput setaf 2 # Set text color to green.
echo "SSH key copied to clipboard."
else
tput setaf 1 # Set text color to red.
echo "SSH key failed to copy to clipboard but you can manually copy it above."
fi
else
echo "SSH key does not exist."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment