feat(export_browser_history): basic arg parsing error message

This commit is contained in:
Phil Crockett 2025-02-16 08:31:21 +01:00
parent 0043b59bc8
commit 2ff3fc434e

View file

@ -11,10 +11,10 @@
# firefox_bookmarks.json # firefox_bookmarks.json
# safari_history.json # safari_history.json
BROWSER_TO_EXPORT="${1?Please specify --chrome, --firefox, or --safari}"
OUTPUT_DIR="$(pwd)" OUTPUT_DIR="$(pwd)"
if [[ "$1" == "--chrome" ]]; then export_chrome() {
# Google Chrome / Chromium
if [[ -e "$2" ]]; then if [[ -e "$2" ]]; then
cp "$2" "$OUTPUT_DIR/chrome_history.db.tmp" cp "$2" "$OUTPUT_DIR/chrome_history.db.tmp"
else else
@ -30,10 +30,9 @@ if [[ "$1" == "--chrome" ]]; then
rm "$OUTPUT_DIR"/chrome_history.db.* rm "$OUTPUT_DIR"/chrome_history.db.*
echo "Chrome history exported to:" echo "Chrome history exported to:"
echo " $OUTPUT_DIR/chrome_history.json" echo " $OUTPUT_DIR/chrome_history.json"
fi }
if [[ "$1" == "--firefox" ]]; then export_firefox() {
# Firefox
if [[ -e "$2" ]]; then if [[ -e "$2" ]]; then
cp "$2" "$OUTPUT_DIR/firefox_history.db.tmp" cp "$2" "$OUTPUT_DIR/firefox_history.db.tmp"
else else
@ -67,10 +66,9 @@ if [[ "$1" == "--firefox" ]]; then
echo "Firefox history exported to:" echo "Firefox history exported to:"
echo " $OUTPUT_DIR/firefox_history.json" echo " $OUTPUT_DIR/firefox_history.json"
echo " $OUTPUT_DIR/firefox_bookmarks.json" echo " $OUTPUT_DIR/firefox_bookmarks.json"
fi }
if [[ "$1" == "--safari" ]]; then export_safari() {
# Safari
if [[ -e "$2" ]]; then if [[ -e "$2" ]]; then
cp "$2" "$OUTPUT_DIR/safari_history.db.tmp" cp "$2" "$OUTPUT_DIR/safari_history.db.tmp"
else else
@ -85,4 +83,15 @@ if [[ "$1" == "--safari" ]]; then
rm "$OUTPUT_DIR"/safari_history.db.* rm "$OUTPUT_DIR"/safari_history.db.*
echo "Safari history exported to:" echo "Safari history exported to:"
echo " $OUTPUT_DIR/safari_history.json" echo " $OUTPUT_DIR/safari_history.json"
}
if [[ "$BROWSER_TO_EXPORT" == "--chrome" ]]; then
export_chrome "$@"
elif [[ "$BROWSER_TO_EXPORT" == "--firefox" ]]; then
export_firefox "@"
elif [[ "$BROWSER_TO_EXPORT" == "--safari" ]]; then
export_safari "$@"
else
echo "Unrecognized argument: $1" >&2
exit 1
fi fi