Created
January 14, 2020 04:29
-
-
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
This file contains 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
# 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