Created
January 28, 2022 02:35
-
-
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.
This file contains hidden or 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
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