Skip to content

Instantly share code, notes, and snippets.

@ffledgling
Last active April 11, 2018 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffledgling/286bb41465840c23147c9bacd5403e97 to your computer and use it in GitHub Desktop.
Save ffledgling/286bb41465840c23147c9bacd5403e97 to your computer and use it in GitHub Desktop.
Useful utility functions for bash
#!/bin/bash
# Can be sourced, or just copy the function you need
# Index
# * openremotefile REMOTE FILENAME
# : Downloads a file from the remote and opens it for viewing on your local machine. Useful when no X/VNC on remote.
openremotefile() {
REMOTE=$1
FILENAME=$2
DIR=/tmp/remotefilecache/
if [[ $(uname) == "Darwin" ]]; then
OPEN="open"
elif [[ $(uname) == "Linux" ]]; then
OPEN="xdg-open"
fi
mkdir -p ${DIR}
pushd ${DIR}
scp ${REMOTE}:${FILENAME} .
$OPEN $(basename ${FILENAME})
popd
}
@ffledgling
Copy link
Author

ffledgling commented Apr 11, 2018

TODO:
Doesn't hanlde special chars/spaces etc - Quoting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment