Last active
April 11, 2018 12:25
-
-
Save ffledgling/286bb41465840c23147c9bacd5403e97 to your computer and use it in GitHub Desktop.
Useful utility functions for bash
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
#!/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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO:
Doesn't hanlde special chars/spaces etc - Quoting.