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"
|
|
|
|
}
|
|
|
|
|
2021-11-07 22:02:31 -08:00
|
|
|
while getopts 'cdrqC' OPT; do
|
2021-10-29 22:49:52 -07:00
|
|
|
case "$OPT" in
|
2021-11-07 22:02:31 -08:00
|
|
|
c)
|
|
|
|
log "Creating database..."
|
|
|
|
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
|
|
|
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
|
|
|
log "Created database..."
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
log "Deleting database..."
|
|
|
|
echo "$DIR/$DB"
|
|
|
|
rm "$DIR/$DB"
|
|
|
|
log "Database deleted..."
|
|
|
|
;;
|
2021-10-29 22:49:52 -07:00
|
|
|
|
2021-11-07 22:02:31 -08:00
|
|
|
r)
|
|
|
|
log "Deleting database..."
|
|
|
|
rm -rf "$DIR"/"$DB"
|
|
|
|
mkdir -p "$DIR"
|
|
|
|
log "Database deleted..."
|
|
|
|
log "Creating database..."
|
|
|
|
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
|
|
|
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
|
|
|
log "Created database..."
|
|
|
|
;;
|
|
|
|
q)
|
|
|
|
log "Connecting to database..."
|
|
|
|
sqlite3 "$DIR/$DB"
|
|
|
|
log "Ending connection to databse..."
|
|
|
|
;;
|
|
|
|
C)
|
|
|
|
log "Cleaning up database..."
|
|
|
|
stmt="DELETE FROM search_history WHERE anime_name IS NULL or anime_name = ''"
|
|
|
|
log "Cleaning up search history..."
|
|
|
|
sqlite3 "$DIR/$DB" <<<"$stmt"
|
|
|
|
stmt="DELETE FROM watch_history WHERE anime_name IS NULL or anime_name = ''"
|
|
|
|
log "Cleaning up watch history..."
|
|
|
|
sqlite3 "$DIR/$DB" <<<"$stmt"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
log "Does not exist or not implemented yet..."
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-10-29 22:49:52 -07:00
|
|
|
esac
|
|
|
|
done
|