Created
September 13, 2023 18:35
-
-
Save n8henrie/04b39532ab19eda9cd5653e527490a3d to your computer and use it in GitHub Desktop.
pbopy: copy over ssh to a MacOS host's clipboard
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
#!/bin/bash | |
set -Eeuf -o pipefail | |
readonly SSH_PORT=1234 | |
readonly USERNAME=me | |
readonly SSH_KEY=/home/"${USERNAME}"/.ssh/my_key_id_rsa | |
readonly DEST=my_machine_name | |
main() { | |
# https://stackoverflow.com/questions/20046804/can-i-test-for-an-open-stdin-stream-from-within-a-bash-script | |
if [[ -t 0 ]]; then | |
# No stdin available | |
tmux save-buffer - | pbcopy | |
else | |
# stdin available | |
# https://stackoverflow.com/questions/12524308/bash-strip-trailing-linebreak-from-output | |
cat | sed --null-data '$ s/\n$//' | ssh -T -p "${SSH_PORT}" -4 -i "${SSH_KEY}" "${USERNAME}@$(tailscale ip -4 "${DEST}")" | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment