Last Updated: February 25, 2016
· sapegin

Shell script to upload current folder to server

Upload current directory to special directory on hosting and copy link to clipboard. Skip .git and node_modules. Just tweak $server, $remote and $url variables and add this function to your .bash_profile.

function yay() {
    server="locum"  # Server (can be ~/.ssh/config alias) 
    dir=`basename "$(pwd)"`
    remote="~/projects/yay/$dir"  # Path on remote server
    url="$dir/"  # Public URL

    tar cp --exclude '.git' --exclude 'node_modules' . | gzip | ssh $server "mkdir -p "$remote"; gzip -cd | tar x -C "$remote""

    echo "Current directory uploaded to $url."
    if command -v pbcopy >/dev/null 2>&1; then
        echo -n "$url" | pbcopy
        echo "URL copied to clipboard."

Then you can just type yay in any folder and it contents will be uploaded to{dirname}/.

1 Response
Add your response


over 1 year ago ·