Improve listing tags

This commit is contained in:
Lukáš Kucharczyk 2022-11-11 13:20:11 +01:00
parent c1564178fa
commit face6e04a6
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 16 additions and 2 deletions

18
tag.sh
View File

@ -15,9 +15,21 @@ fail() {
}
listtags() {
# $FILENAME $LIMIT
[ -z "$1" ] && fail "No filename supplied."
FILENAME="$1"
sqlite3 -table "$DB_FILE" "SELECT filename, label from files INNER JOIN tags_ties ON tags_ties.fid = files.fid INNER JOIN tags ON tags.tid = tags_ties.tid WHERE filename = \"$FILENAME\""
shift
LIMIT="${1:-0}"
ADDITIONAL_QUERY=""
[ $LIMIT -gt 0 ] && ADDITIONAL_QUERY="LIMIT $LIMIT"
sqlite3 -table "$DB_FILE" \
"SELECT filename, label from files \
INNER JOIN tags_ties ON tags_ties.fid = files.fid \
INNER JOIN tags ON tags.tid = tags_ties.tid \
WHERE filename = \"$FILENAME\"\
$ADDITIONAL_QUERY"
}
if [[ "$1" = "add" ]]; then
@ -58,13 +70,15 @@ if [[ "$1" = "tag" ]]; then
FILENAME="$1"
shift
[ -z "$1" ] && fail "No tag supplied."
COUNTER=0
while true; do
LABEL="$1"
shift
sqlite3 -table "$DB_FILE" "INSERT INTO tags_ties (fid, tid) VALUES ((SELECT fid FROM files WHERE filename = \"$FILENAME\"),(SELECT tid FROM tags WHERE label = \"$LABEL\"))"
COUNTER=$((COUNTER++))
[ -z "${1:-}" ] && break
done
listtags "$FILENAME"
listtags "$FILENAME" "$COUNTER"
exit 0
fi