Improve listing tags
This commit is contained in:
parent
c1564178fa
commit
face6e04a6
18
tag.sh
18
tag.sh
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue