Skip to content

Instantly share code, notes, and snippets.

@alexcu
Last active October 30, 2017 03:46
Show Gist options
  • Save alexcu/a63b94e9e0e1ffa2d808cc09b8a6de1c to your computer and use it in GitHub Desktop.
Save alexcu/a63b94e9e0e1ffa2d808cc09b8a6de1c to your computer and use it in GitHub Desktop.
Get the major and minor versions of macOS from the command line
# Gets the macOS major/minor versions
mac_os_major_version=$(sw_vers | grep "ProductVersion:" | sed -e 's/.*10\.\([0-9][0-9]\).*/\1/')
mac_os_minor_version=$(sw_vers | grep "ProductVersion:" | sed -e 's/.*10\.[0-9][0-9]\(.*\)/\1/')
# macOS Sierra 10.12.2 requires extra config in .ssh/config
# See https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
if [ $((mac_os_major_version)) -gt 12 ] ||
([ $((mac_os_major_version)) -eq 12 ] && [ $((mac_os_minor_version)) -ge 0.2 ]); then
cat << EOF >> ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
EOF
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment