Skip to content

Instantly share code, notes, and snippets.

@tunaranch
Last active December 15, 2015 05:48
Show Gist options
  • Save tunaranch/5211210 to your computer and use it in GitHub Desktop.
Save tunaranch/5211210 to your computer and use it in GitHub Desktop.
Quick and dirty sh script to copy a file's location to clipboard, so you can paste it into an scp command. OS X only
#!/bin/sh
#Usage: coordinates.sh foo.txt
# realpath function from http://stackoverflow.com/questions/3572030/bash-script-absolute-path-with-osx
USER=`whoami`
IP=`ifconfig en0 inet | grep "inet" | awk -F\ '{print $2}'`
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
PATH=$(realpath "$1")
COORDS="${USER}@${IP}:${PATH}"
printf "${COORDS}" | /usr/bin/pbcopy
echo "Copied scp coordinates [${COORDS}] to clipboard"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment