2021-10-29 22:49:52 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-11-01 03:16:38 -07:00
|
|
|
DIR="$XDG_CONFIG_HOME/ani-cli"
|
2021-10-29 22:49:52 -07:00
|
|
|
DB='history.sqlite3'
|
|
|
|
|
2021-10-30 00:53:18 -07:00
|
|
|
log() {
|
|
|
|
printf "%s\n" "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts 'cdrq' OPT; do
|
2021-10-29 22:49:52 -07:00
|
|
|
case "$OPT" in
|
|
|
|
c)
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Creating database..."
|
2021-10-30 11:27:37 -07:00
|
|
|
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
|
|
|
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Created database..."
|
2021-10-29 22:49:52 -07:00
|
|
|
;;
|
|
|
|
d)
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Deleting database..."
|
2021-10-30 12:38:42 -07:00
|
|
|
echo "$DIR/$DB"
|
|
|
|
rm "$DIR/$DB"
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Database deleted..."
|
2021-10-29 22:49:52 -07:00
|
|
|
;;
|
|
|
|
|
|
|
|
r)
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Deleting database..."
|
|
|
|
rm -rf "$DIR"/"$DB"
|
2021-10-30 11:27:37 -07:00
|
|
|
mkdir -p "$DIR"
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Database deleted..."
|
|
|
|
log "Creating database..."
|
2021-10-30 11:27:37 -07:00
|
|
|
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
|
|
|
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Created database..."
|
|
|
|
;;
|
|
|
|
q)
|
|
|
|
log "Connecting to database..."
|
2021-10-30 12:38:42 -07:00
|
|
|
sqlite3 "$DIR/$DB"
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Ending connection to databse..."
|
2021-10-29 22:49:52 -07:00
|
|
|
;;
|
|
|
|
*)
|
2021-10-30 00:53:18 -07:00
|
|
|
log "Don't get here"
|
2021-10-29 22:49:52 -07:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|