Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Created January 14, 2020 04:29
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 tjluoma/f36c549f427e577dcd5018e1b1b9c7a9 to your computer and use it in GitHub Desktop.
Save tjluoma/f36c549f427e577dcd5018e1b1b9c7a9 to your computer and use it in GitHub Desktop.
shell commands to parse the ~/.dropbox/info.json file and determine where Dropbox is installed
# If you have a 'work' or 'business' Dropbox and a 'personal' one,
# this will only work on the 'personal' one
JSON="$HOME/.dropbox/info.json"
if [[ ! -e "$JSON" ]]
then
echo "$NAME: '$JSON' file not found." >>/dev/stderr
exit 2
fi
# 'jq' makes dealing with JSON much easier, but it isn't installed by default
if (( $+commands[jq] ))
then
DROPBOX_PATH=$(jq -r '.personal.path' "$JSON")
else
DROPBOX_PATH=$(fgrep '"personal":' "$JSON" | sed 's#.*"path": "##g ; s#", .*##g')
fi
if [[ "$DROPBOX_PATH" == "" ]]
then
echo "$NAME: Unable to determine Dropbox path." >>/dev/stderr
exit 2
fi
if [[ ! -d "$DROPBOX_PATH" ]]
then
echo "$NAME: Dropbox path '$DROPBOX_PATH' is not a directory." >>/dev/stderr
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment