Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active June 4, 2023 12:02
Show Gist options
  • Star 72 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save idleberg/6c8a563e248103baaa20 to your computer and use it in GitHub Desktop.
Save idleberg/6c8a563e248103baaa20 to your computer and use it in GitHub Desktop.
Ignore node_modules/bower_components folders in your Dropbox

This script scans your Dropbox (or any given folder) for folders stored in the ignore array and excludes them from syncing. Makes use of the official Dropbox CLI

I'm a beginner at bash, so all improvements are welcome!

#!/bin/bash

set -e

# SETTINGS
# ========
# Location of your Dropbox folder
dropbox_folder="/Users/YOUR_NAME/Dropbox"
# Location of dropbox.py (http://www.dropboxwiki.com/tips-and-tricks/using-the-official-dropbox-command-line-interface-cli)
dropbox_script="~/bin/dropbox.py"
# Array of folders to ignore
ignore_list=['bower_components','node_modules','vendor']

# FUNCTIONS
# =========
function dropbox_install(){
    while true; do
        read -p $'\nDo you want to use download and install dropbox.py? (y/n) ' yn
        case $yn in
            [Yy]* )
                dropbox_script_parent=$(dirname $dropbox_script)
                mkdir -p $dropbox_script_parent
                wget -O $dropbox_script "https://www.dropbox.com/download?dl=packages/dropbox.py"
                chmod +x $dropbox_script
                recurse $dropbox
                break;;
            [Nn]* )
                echo 'Aborted. See http://www.dropboxwiki.com/tips-and-tricks/using-the-official-dropbox-command-line-interface-cli#Installation for manual instructions.';
                exit 1;;
        esac
    done
}

function recurse() {
 for i in "$1"/*;do
    if [ -d "$i" ];then
        j=$(basename "$i")
        if [[ " ${ignore_list[*]} " == *$j* ]]; then
            $dropbox_script exclude "$i"
        fi
        recurse "$i"
    fi
 done
}

# SCRIPT
# ======
# Check Dropbox folder location
if [ -d "$dropbox_folder" ];then
    echo "Dropbox found at $dropbox_folder"
else
    echo "Dropbox not found"
    exit 1
fi

# Check for dropbox.py
if [ -e "$dropbox_script" ];then
    recurse $dropbox
else
    dropbox_install
fi
@idleberg
Copy link
Author

idleberg commented Nov 6, 2022

It's 2022, and I'm now using Maestral (@samschott/maestral)

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