Skip to content

Instantly share code, notes, and snippets.

@wenkokke
Last active August 29, 2015 14:16
Show Gist options
  • Save wenkokke/bda4911d58474e401f91 to your computer and use it in GitHub Desktop.
Save wenkokke/bda4911d58474e401f91 to your computer and use it in GitHub Desktop.
Bash command for Dropbox Share...
DROPBOX_SIZE_LIMIT=3000
DROPBOX_FOLDER="$HOME/Dropbox"
DROPBOX_SHARED_INDEX="$DROPBOX_FOLDER/Shared/.index"
function share {
current=`du -s $DROPBOX_FOLDER | cut -f1`
# with no arguments, echo current usage
if [ "$#" -eq 0 ]; then
current_percent=`bc <<< "scale=2; ($current/$DROPBOX_SIZE_LIMIT)*100"`
echo "Currently using ${current}M (${current_percent}%) of Dropbox folder"
return
fi
# check if first argument is a file or directory
if [ ! -f $1 ] && [ ! -d $1 ]; then
echo "'$1' is not a file or directory"
return
fi
# ask for confirmation if the file is large
new=`du -s $1 | cut -f1`
if (( new > 50 )); then
read -p "'$1' is large (${new}M), continue? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return
fi
fi
# ask for confirmation if file pushes Dropbox over limit
total=$(( current + new ))
if (( total > DROPBOX_SIZE_LIMIT )); then
read -p "Sharing '$1' will push Dropbox folder over the size limit, continue? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return
fi
fi
echo "Sharing '$1' to Dropbox..."
mv "$1" "$DROPBOX_FOLDER/Shared/"
ln -s "$DROPBOX_FOLDER/Shared/$(basename $1)" "$1"
echo "$DROPBOX_FOLDER/Shared/$(basename $1) $(readlink $1)" >> $DROPBOX_SHARED_INDEX
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment